Message-ID: <CAJ55+dJGga2TVxN_2KfnYHVWighCp5fgnRhHgEVEPPzXfpYfTg@mail.gmail.com>
Date: 2012-10-19T22:10:34Z
From: Thomas Lumley
Subject: setting option in function
In-Reply-To: <CAKctRd3mh4xK2+09yCvqi1fM2REMGQtQj1A=1M7voxcqw7r1Zw@mail.gmail.com>
old_options <- options(na.action=na.fail)
on.exit(options(old_options))
You can also use this to define a wrapper that executes an expression
using special options
withOptions<-function(optlist,expr){
oldopt<-options(optlist)
on.exit(options(oldopt))
expr<-substitute(expr)
eval.parent(expr)
}
-thomas
On Sat, Oct 20, 2012 at 10:35 AM, Charles Geyer <charlie at stat.umn.edu> wrote:
> is it possible to set an option inside a function ((I want to set
> na.action = na.fail) and have the previous state restored if there is
> an error so that the function doesn't change the option behind the
> user's back?
>
> Sorry if this has been answered before, but this subject is hard to Google.
>
> --
> Charles Geyer
> Professor, School of Statistics
> University of Minnesota
> charlie at stat.umn.edu
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
--
Thomas Lumley
Professor of Biostatistics
University of Auckland