Re: [R] setting options only inside functions

From: William Dunlap <wdunlap_at_tibco.com>
Date: Wed, 27 Apr 2011 14:41:01 -0700

> From: h.wickham@gmail.com [mailto:h.wickham@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)



R-help_at_r-project.org 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. Received on Wed 27 Apr 2011 - 21:44:56 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 27 Apr 2011 - 21:50:34 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive