Re: [R] setting options only inside functions

From: Hadley Wickham <>
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.


Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University

______________________________________________ mailing list
PLEASE do read the posting guide
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 Please read the posting guide before posting to the list.

list of date sections of archive