Re: [R] setting options only inside functions

From: <>
Date: Wed, 27 Apr 2011 15:45:16 -0500

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.



On Wed, 27 Apr 2011, Hadley Wickham wrote:

>> 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

Luke Tierney
Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:
Iowa City, IA 52242                 WWW:

______________________________________________ mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code.

Received on Wed 27 Apr 2011 - 20:48:47 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 Please read the posting guide before posting to the list.

list of date sections of archive