From roebuck at mdanderson.org  Mon Feb 20 20:46:42 2006
From: roebuck at mdanderson.org (Paul Roebuck)
Date: Mon, 20 Feb 2006 13:46:42 -0600 (CST)
Subject: [Rd] invalid graphics state using dev.print (fwd)
In-Reply-To: <Pine.LNX.4.64.0602200714030.3798@gannet.stats.ox.ac.uk>
References: <Pine.OSF.4.58.0602081515590.512812@wotan.mdacc.tmc.edu>
	<17388.51930.273876.336070@stat.math.ethz.ch>
	<43F92420.4070706@stat.auckland.ac.nz>
	<Pine.LNX.4.64.0602200714030.3798@gannet.stats.ox.ac.uk>
Message-ID: <Pine.OSF.4.58.0602201205190.67951@wotan.mdacc.tmc.edu>

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.

Might have snapped to this if the error message had said something
less vague.

> > 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)

What is the recommended method of converting width/height
from inches to pixels (preserving aspect ratio), even if
ambiguous?

> ..., 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.

Perhaps an extra attribute could be added to each device
where attr("type") = c("bitmap", "vector")

> str(dev.cur())
 Named int 2
 - attr(*, "names")= chr "quartz"
 - attr(*, "type")= chr "vector"

> BTW, I think it was perverse to call dev.print() except to do printing.

I was making a hardcopy of my plot which IMO would seem
a legitimate usage. Don't understand your "perverse"
comment here. Alternative recommendation?

----------------------------------------------------------
SIGSIG -- signature too long (core dumped)



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