Skip to content

Odd quartz behavior on 24" iMac at 10.7.5

7 messages · Simon Urbanek, Ray Spence

#
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. 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:
$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
#
Ray,
On Oct 15, 2012, at 8:57 PM, Ray Spence wrote:

            
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:
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
1 day later
#
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?

Thanks again
Ray
On 10/15/12 6:32 PM, Simon Urbanek wrote:

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

            
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
#
Hi Simon,

I'll write in line below -
On 10/17/12 11:34 AM, Simon Urbanek wrote:
I've done this. Here is the output

host:~# ./disp
262.194mm x 324.255mm
host:~#

Which doesn't look correct (?).
Ok - now a formal question - are you saying that you/R Team can provide 
a patch
of sorts?

Thanks again Simon,
Ray

  
    
#
On Oct 17, 2012, at 3:01 PM, Ray Spence wrote:

            
Is this on the machine that reported 0 in R? Also are you running this as the same user? (I'm a bit wary given the root hash ...).
Possibly ...
#
Hi Simon,
On 10/17/12 12:46 PM, Simon Urbanek wrote:
Good point - I ran disp as root. On the problem host in question I'll run
disp as non-root:

host:/tmp$ ./disp
Oct 17 13:22:02 host.berkeley.edu disp[12852] <Error>: kCGErrorFailure: 
Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged.
0mm x 0mm
host:/tmp$

Which is also clearly messed up.
Ok - I'll look into somehow getting this issue in front of Apple. In the 
meantime
We'll hardcode a dpi setting (probably 94) for R on these iMacs.

Thanks again,
Ray