[Rd] invalid graphics state using dev.print (fwd)

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Feb 20 09:37:47 CET 2006


On Mon, 20 Feb 2006, Prof Brian Ripley wrote:

> On Mon, 20 Feb 2006, Paul Murrell wrote:
>
> [...]
>
>>>   >> x11()
>>>   >> plot(rnorm(10))
>>>   >> dev.print(png)
>
>>>     Paul> Error in dev.copy(device = function (filename = "Rplot%03d.png", width =
>>>     Paul> 480,  :
>>>     Paul> invalid graphics state
>
>> I think the problem is that the width and height of the PNG device is
>> being taken (without regard for units) from the X11 device.  So
>> approximately 7 inches square screen window gets drawn into
>> approximately 7 *pixel* square PNG file and (understandably) R complains
>> that there is not enough room for the plot.
>
> Yes, that it how it is documented to work.
>
>> Another workaround is something like ...
>>
>> dev.print(png, width=480, height=480)
>
> (Just one will do if you want to preserve the aspect ratio.)
>
>> ... and a fix requires making dev.print() smarter so that it figures out
>> that it needs to convert width/height from inches to pixels.
>
> I don't think there is a way to do that unambiguously (there is no
> standard way to do the conversion), and in any case dev.print() was passed
> a function, not the name of a function, and so does not in general know
> how it behaves (and your 'png' need not be R's png()).
>
> All we can do is to re-emphasize this on the help page, and add a warning
> if a known bitmap device is detected (possibly inaccurately) by name.

One more thing we can do is to get the devices to issue a warning if the 
'width' and 'height' arguments appear inappropriate.  Since one might want 
to produce long thin plots, I've decided to do so if
width < 20 && height < 20.   Even those are just about plausible if you 
were trying to produce a small icon.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list