Skip to content
Prev 220936 / 398500 Next

Are there better ways to save and restore par() settings

On May 14, 2010, at 5:45 PM, Duncan Murdoch wrote:

            
In the examples from help(par) I see:
p <- par(mfrow = c(2, 2),
# 2 x 2 pictures on one plot pty = "s")
  # square plotting region,
  # independent of device size
  ## At end of plotting, reset to previous settings:
par(op)
# Alternatively, op <- par(no.readonly = TRUE)
# the whole list of settable par's.
## do lots of plotting and par(.) calls, then reset: par(op)
## Note this is not in general good practice
Was it only with the use of the "no.read.only" parameter that one is  
supposed to avoid the form I illustrated. I had assumed it applied to  
both alternatives.
Perhaps it was implied in a manner to which I was not properly  
receptive. The only place I see on.exit() on the par help page is in  
the final example. I do not see a link to that function in the that  
help page, and I had read it but assumed it was related to "exit"-ing  
an R session. On visiting the on.exit help page for the first time in  
my life, I see that its primary use is with graphics device calls. So  
we are being advised to write that wrapper function each time we might  
be making a par-changing plot?