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

From: Paul Roebuck <roebuck_at_mdanderson.org>
Date: Mon 20 Feb 2006 - 19:46:42 GMT

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

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

R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue Feb 21 06:51:52 2006

This archive was generated by hypermail 2.1.8 : Tue 21 Feb 2006 - 03:44:41 GMT