[R] Default par() options

Bert Gunter gunter.berton at gene.com
Thu Mar 1 23:59:17 CET 2007


Thomas:
I am not sure exactly what you are asking for below, but I wonder if your
query could be satisfied by the judicious use of the ... argument in a
wrapper function to par(), like

myPar=function(bg="lightgray", pch=19,...)par(bg=bg,pch=pch,...)

or perhaps 

myX11 <- function(width=10, bg="lightgray", pch=19,...)
{
X11(width=width)
par(bg=bg,pch = pch,...)
}

This would use the existing user-chosen defaults for the respective devices
if no other values were provided, and would allow the user to explicitly
specify any different values for them or additional arguments to par if
needed. I agree that it ain't elegant, though, so I'd welcome better
alternatives, too.

Of course, one can explicitly use formals() and the construction:

dots <- as.list(substitute(list(...)))[-1]   ## V&R: S PROGRAMMING p. 46

to obtain all the arguments and their names and appropriately stuff them
into either par() or X11() using do.call() or something similar; but that
seems like more than you need here.

Anyway, HTH.


-- Bert Gunter
Genentech Non-Clinical Statistics
South San Francisco, CA
 
"The business of the statistician is to catalyze the scientific learning
process."  - George E. P. Box
 
 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Petr 
> Klasterecky
> Sent: Thursday, March 01, 2007 12:51 PM
> To: Thomas Friedrichsmeier
> Cc: r-help at r-project.org
> Subject: Re: [R] Default par() options
> 
> I am no expert on these topics but currently I am solving a similar 
> issue using the .Rprofile file and the .First function. So maybe it's 
> enough to put
> .First <- function(){
> par(whatever you want)
> further instructions if neccessary
> }
> 
> Petr
> 
> Thomas Friedrichsmeier napsal(a):
> > The following question/idea came up on the RKWard 
> development mailing list, 
> > but might be of general interest:
> > 
> > Is there a nice way to customize the default look of all 
> graphs on all 
> > devices? I.e. a way to - for instance - set the following 
> options before each 
> > plot:
> > 
> > par(bg="light gray", las=2, pch=19)
> > 
> > As far as I have found, there would currently be two ways 
> to do this:
> > 1) Adding the above statement manually after opening the 
> device, and before 
> > starting the plot. It could of course be wrapped inside a 
> custom function to 
> > save some typing, but you'd still need to make sure to 
> always add the 
> > command.
> > 
> > 2) Overriding all device functions with something like:
> > X11 <- function (...) {
> > 	grDevices::X11 (...)
> > 	par ([custom options])
> > }
> > This would be feasible, but feels rather dirty. Also, 
> something substantially 
> > more elaborate would be needed to honor e.g. fonts and bg 
> arguments, if 
> > explicitely specified in the call to X11. Would have to be 
> done for each 
> > device separately.
> > 
> > Does a third, more elegant solution exist?
> > 
> > If not, would the following idea have any chances of being 
> added to R?
> > 
> > Create a new options("par.default"), similar to the already 
> existing 
> > options("par.ask.default"). This would take a list of par() 
> options to set a 
> > default value for, like e.g.:
> > 
> > options(par.default=list(bg="light gray", las=2, pch=19))
> > 
> > Only those options would need to be specified in the list, 
> for which you 
> > actually want to set a default different from the built-in. Options 
> > explicitely specified in X11(), plot(), additional calls to 
> par(), etc. would 
> > take precedence over options("par.default").
> > 
> > Regards
> > Thomas Friedrichsmeier
> > 
> > 
> > 
> --------------------------------------------------------------
> ----------
> > 
> > ______________________________________________
> > R-help at 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
> > and provide commented, minimal, self-contained, reproducible code.
> 
> -- 
> Petr Klasterecky
> Dept. of Probability and Statistics
> Charles University in Prague
> Czech Republic
> 
> ______________________________________________
> R-help at 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
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list