[R] Q: calling par() in .First()

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Aug 6 21:27:36 CEST 2007

On Mon, 6 Aug 2007, Greg Snow wrote:

> Be aware that the effects of calls to par usually only last for the
> duration of the graphics device, not the R session.

They always apply to the current device only (and will create a current 
device if possible).

> If you put a call to par in your startup script, then it will open a 
> graphics device and set the option, but if you close that graphics 
> device and do another plot then a new graphics device will be started 
> with the default parameters rather than what you set in the startup 
> script.
> You can set some of the options (including background color) when
> starting a graphics device, that may be the better option.

You can also set a hook (see ?setHook) on plot.new (see its help page), 
which could be used to set par(bg=).  A hook on package grDevices would 
have avoided the reported error messages.  (Calling graphics::par in 
startup code works in R-devel but not in 2.5.x, but using hooks works in 
any fairly recent R.)

> There was some discussion a while back on having global options for some
> of the graphics defaults, but I don't think anything has been
> implemented yet.

I don't believe there was agreement that was desirable.

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-help mailing list