Skip to content
Prev 36448 / 63424 Next

grid.cap() requires more time?

Baptiste,

first, there is a mailing list specifically for Mac questions - R-SIG-Mac.

Now to your post - grid.cap captures the screen of the device which has two implications here:

a) Quartz is asynchronous -- i.e. is doesn't actually draw the content on screen until you're finished with drawing (for efficiency). Unfortunately R has no provision to tell the graphics device that it's done with drawing (you can always add another lines() etc.) so Quartz is simply guessing by measuring the time between draw commands. So when you run grid.cap while the output has not been drawn yet (i.e. immediately after the last drawing command) it will be empty as there is no content yet since Quartz is waiting for the end.

b) it will contain the resize mark because it is a screen shot so the mark is actually part of it (this is intentional).

If what you really want is a bitmap from the device, it's better to use quartz.save instead (followed by readPNG if you want the bitmap as raster) -- that actually re-runs the plot in a separate quartz device that is not on-screen so neither of the above are an issue. 

That said, you can file a) as a bug against Mac version of R (at https://bugs.r-project.org/ ) since grid.cap should actually trigger the flush before it does the capture. I cannot promise that the fix will make it to 2.11.0, though, because it may be non-trivial to trigger the asynchronous flush and wait for it without blocking something (I'll have to look).

Thanks,
Simon
On Apr 17, 2010, at 6:34 AM, baptiste auguie wrote: