Re: [R] setting options only inside functions

From: Hadley Wickham <hadley_at_rice.edu>
Date: Wed, 27 Apr 2011 13:58:29 -0500

> This has the side effect of ignoring errors
> and even hiding the error messages.  If you
> are concerned about multiple calls to on.exit()
> in one function you could define a new function
> like
>  withOptions <- function(optionList, expr) {
>   oldOpts <- options(optionList)
>   on.exit(options(oldOpts))
>   expr # lazily evaluate
>  }

I wish R had more functions like this. This sort of behaviour is also useful when you open connections or change locales. Ruby's blocks provide nice syntactic sugar for this idea.

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

______________________________________________
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 - 19:02:12 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:00:33 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