[R] Can I set default parameters for the default graphics device?

Erik Iverson eriki at ccbr.umn.edu
Fri Jul 16 02:43:08 CEST 2010


On 07/15/2010 07:10 PM, James wrote:
> I'm completely new to R, and I'd like to do something like this:
>
>      >  x=c(1,2,3)
>      >  plot(x,x)
>
> At this point, R creates a file "Rplots.pdf", since the default device is
> PDF and the default filename is "Rplots.pdf".

Since you're completely new to R, I might ask what OS you're using, and if 
you're using R interactively?  If you are using R interactively, the default 
device would probably create a new 'window' to display the graphic in.  If 
you're running in batch mode, then pdf is the default.


I know I can set the default
> device like this:
>
>      >  options(device="png")
>
> But is there a way to set the default device's default filename?

I guess you can probably just write your own wrapper function and use that as 
the device name.

Try:

mypng <- function(filename = "mydefault.png", ...) {
    png(filename, ...)
}

options(device = "mypng")

I did not test any of this, but I hope it works.



More information about the R-help mailing list