Re: [R] how to specify dev.print target by a variable?

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Fri 23 Dec 2005 - 18:51:44 EST

On Fri, 23 Dec 2005, Berwin A Turlach wrote:

> G'day Leif,
>
>>>>>> "LK" == Leif Kirschenbaum <leif@reflectivity.com> writes:
>
> LK> How do I do this such that I can specify FOO to be one of
> LK> several choices? (GDD, PNG, postscript, etc.) If I make FOO a
> LK> character variable, then "dev.print" complains.
> Mmh, I am not sure what the complaint of R 2.2.0 on MS Windows is, but
> I guess it is the same as under linux:
>
>> DEVw=500
>> DEVh=350
>> fname="my_plot"
>> plot(rnorm(300))
>> FOO <- "png"
>> dev.print(file=fname, device=FOO, width=DEVw, height=DEVh, bg="transparent")
> Error in dev.copy(device = "png", file = fname, width = DEVw, height = DEVh, :
> 'device' should be a function
>
> Which is very informative. `device' is supposed to be a function, not
> a character variable, thus:
>
>> FOO <- png
>> dev.print(file=fname, device=FOO, width=DEVw, height=DEVh, bg="transparent")
> X11
> 2
>> FOO <- pdf
>> dev.print(file=fname, device=FOO, width=DEVw, height=DEVh, bg="transparent")
> X11
> 2
>
> all seem to work.

And my guess is that Leif wants to be able to do

mydevice <- "png"
dev.print(device = get(mydevice), ...)

                    ^^^

-- 
Brian D. Ripley,                  ripley@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

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri Dec 23 19:02:53 2005

This archive was generated by hypermail 2.1.8 : Fri 23 Dec 2005 - 23:39:33 EST