[R] setting options only inside functions
William Dunlap
wdunlap at tibco.com
Wed Apr 27 23:41:01 CEST 2011
> From: h.wickham at gmail.com [mailto:h.wickham at gmail.com] On
> Behalf Of Hadley Wickham
> Sent: Wednesday, April 27, 2011 2:21 PM
> To: luke-tierney at uiowa.edu
> Cc: William Dunlap; r-help at r-project.org
> Subject: Re: [R] setting options only inside functions
>
> > Put together a list and we can see what might make sense. If we did
> > take this on it would be good to think about providing a reasonable
> > mechanism for addressing the small flaw in this function as it is
> > defined here.
>
> In devtools, I have:
>
> #' Evaluate code in specified locale.
S+ has a Sys.withlocale() that is a bit more general than
your with_locale():
> Sys.withlocale
function(expr, category = "LC_ALL", locale)
{
cur.locale <- Sys.getlocale(category)
on.exit(Sys.setlocale(category = category, locale = cur.locale))
Sys.setlocale(category = category, locale = locale)
expr
}
> with_locale <- function(locale, expr) {
> cur <- Sys.getlocale(category = "LC_COLLATE")
> on.exit(Sys.setlocale(category = "LC_COLLATE", locale = cur))
>
> Sys.setlocale(category = "LC_COLLATE", locale = locale)
> force(expr)
> }
>
> (Using force here just to be clear about what's going on)
>
> Bill discussed options(). Other ideas (mostly from skimming
> apropos("set")):
>
> * graphics devices (i.e. automatic dev.off)
Also, for setting and restoring graphics parameters with par().
> * working directory (as in the chdir argument to sys.source)
> * environment variables (Sys.setenv/Sys.getenv)
> * time limits (as replacement for transient = T)
More information about the R-help
mailing list