[R-SIG-Mac] Odd quartz behavior on 24" iMac at 10.7.5

Simon Urbanek simon.urbanek at r-project.org
Wed Oct 17 20:34:36 CEST 2012


Ray,

On Oct 17, 2012, at 2:17 PM, Ray Spence wrote:

> Hi Simon,
> 
> Thank you very much for your response. I've installed the inline library
> and run the function as you wrote. The results are interesting. Following
> this procedure on a 24" iMac running OS X 10.7.4 I get this:
> 
> > f()
> 518.809mm x 320.842mm
> [1] 1.617021
> >
> 
> which is pretty close to what you predicted. However, doing the same on another
> 24" iMac running OS X 10.7.5 I get this:
> 
> > f()
> 0mm x 0mm
> [1] NaN
> >
> 
> which clearly shows a problem. I know that we can set the quartz dpi variable
> by hand per session or in users' .Rprofile file which will compensate for this
> problem. But I'd like to find a better solution that doesn't require editing any
> user file. I suppose this a bug but am not sure if it would belong to R or
> to Apple?
> 

Apple - their CGDisplayScreenSize() is returning bogus result. Just to make sure, please try this in a standalone program w/o R:

disp.c:

#include <stdio.h>
#include <ApplicationServices/ApplicationServices.h>

int main() {
    CGSize ds = CGDisplayScreenSize(CGMainDisplayID());
    printf("%gmm x %gmm\n", ds.width, ds.height);
    return 0;
}


compile and run via

gcc -o disp disp.c -framework AppKit && ./disp



That said, we can work around that bug in R by not using the screen size when it's bogus but falling back to something around 90-100 dpi. In fact, I'm surprised that it doesn't bomb entirely ...

Thanks,
Simon


> Thanks again
> Ray
> 
> On 10/15/12 6:32 PM, Simon Urbanek wrote:
>> Ray,
>> 
>> On Oct 15, 2012, at 8:57 PM, Ray Spence wrote:
>> 
>>> All,
>>> 
>>> There seems to be something wrong between OS X 10.7.5 and how
>>> quartz reads Apple graphics resolution on 24" iMac (early 2008,
>>> iMac8,1) on R 2.15.1 GUI1.52. On this hardware/OS/R version the
>>> default R plot is a rectangle.
>> Can you attach a screenshot? R is simply reading the geometry reported by the OS to adjust the aspect ratio accordingly.
>> 
>> Can you run this in R:
>> 
>> install.packages("inline") # if you don't have inline installed yet
>> library(inline)
>> f=cfunction(,'CGDirectDisplayID md = CGMainDisplayID(); CGSize ds = CGDisplayScreenSize(md); Rprintf("%gmm x %gmm\\n", ds.width, ds.height); return ScalarReal(ds.width / ds.height);','#include <ApplicationServices/ApplicationServices.h>')
>> f()
>> 
>> You should see this on a 24" iMac8,1:
>> 
>>> f()
>> 520mm x 320mm
>> [1] 1.625
>> 
>> Those are the proper dimensions of the built-in screen.
>> 
>> If that's not what you get, you should be able work around this by setting dpi manually to 94 (it will be slightly off since the native dpi is asymmetric 93.785 x 95.25 but 94 should be close enough to not notice) - either in quartz.options() or quartz().
>> 
>> Cheers,
>> Simon
>> 
>> 
>> 
>>> On same hardware/R version running
>>> OS X 10.7.4 the default R plot is square as expected. (I don't see
>>> this behavior on 20" iMac once upgraded to 10.7.5.)
>>> 
>>> On this problematic iMac, if I run quartz.options() without changing
>>> anything I see:
>>> 
>>>> quartz.options()
>>> $title
>>> 
>>> [1] "Quartz %d"
>>> 
>>> $width
>>> 
>>> [1] 7
>>> 
>>> $height
>>> 
>>> [1] 7
>>> 
>>> $pointsize
>>> 
>>> [1] 12
>>> 
>>> $family
>>> 
>>> [1] "Helvetica"
>>> 
>>> $fontsmooth
>>> 
>>> [1] TRUE
>>> 
>>> $antialias
>>> 
>>> [1] TRUE
>>> 
>>> $type
>>> 
>>> [1] "native"
>>> 
>>> $bg
>>> 
>>> [1] "transparent"
>>> 
>>> $canvas
>>> 
>>> [1] "white"
>>> 
>>> $dpi
>>> 
>>> [1] NA
>>> 
>>> But any plot, eg.
>>>> plot (rnorm(10),rnorm(10))
>>> returns an image that is most definitely not a square.
>>> 
>>> Can anyone help me investigate this? For instance where/how
>>> does R create the plot graphic? Are there specific OS X file(s) that R
>>> reads to generate the plots?
>>> 
>>> My assumption is that this is an Apple Inc. generated problem
>>> but figured that the R community might be a bit more responsive..
>>> 
>>> Thanks,
>>> Ray
>>> 
>>> -- 
>>> *******************
>>> Raymond Spence
>>> U.C. Berkeley
>>> Dept. of Statistics
>>> SCF Sysadmin
>>> 497 Evans Hall
>>> U.C. Berkeley
>>> 510.642.5497
>>> 
>>> _______________________________________________
>>> R-SIG-Mac mailing list
>>> R-SIG-Mac at r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
>>> 
>>> 
> 
> 
> -- 
> *******************
> Raymond Spence
> U.C. Berkeley
> Dept. of Statistics
> SCF Sysadmin
> 497 Evans Hall
> U.C. Berkeley
> 510.642.5497
> *******************
> 
> 



More information about the R-SIG-Mac mailing list