This surprised me, even though it shouldn’t have done. (My false internal model of the world was that oo <- options(); … options(oo) would overwrite the entire options list with the old values.) I wonder if it would be worth pointing out explicitly in ?options.
Writing: wyclif.substack.com Book: www.wyclifsdust.com On Thu, 11 Jul 2024 at 08:03, Greg Jefferis <jeffe...@gmail.com> wrote: > Dear John, > > You need to collect the return value when setting options. This will > include an explicit NULL value for an option that was previously NULL. > > Best, > > Greg Jefferis. > > options(digits.secs = NULL) > > noset2 = function() { > opts <- options(digits.secs = 3) > on.exit(options(opts)) > print(opts) > } > > > getOption("digits.secs") > NULL > > > noset2() > $digits.secs > NULL > > > getOption("digits.secs") > NULL > > Gregory Jefferis > Division of Neurobiology > MRC Laboratory of Molecular Biology > Francis Crick Avenue > Cambridge Biomedical Campus > Cambridge, CB2 OQH, UK > > http://www2.mrc-lmb.cam.ac.uk/group-leaders/h-to-m/g-jefferis > http://jefferislab.org > https://www.zoo.cam.ac.uk/research/groups/connectomics > > > > On 11 Jul 2024, at 06:08, John Muschelli <muschell...@gmail.com> wrote: > > > > When setting options in a function, I have always used the following: > > opts <- options() > > on.exit(options(opts), add = TRUE) > > and assumed it "reset" options to what they were prior to running the > > function. But for some options that are set to NULL, it does not seem to > > reset them. Specifically, I have found digits.secs to be set after this > > simple example below. Is this expected behavior/documented? Overall, > this > > specific example (the one I encountered in the wild) is not that harmful, > > but I wanted to ask before I set a fix for this in our work > > > > noset = function() { > > opts = options() > > print(opts$digits.secs) > > on.exit(options(opts)) > > options(digits.secs = 3) > > } > > getOption("digits.secs") > > #> NULL > > noset() > > #> NULL > > getOption("digits.secs") > > #> [1] 3 > > > > > > John Muschelli, PhD > > Associate Research Professor > > Department of Biostatistics > > Johns Hopkins Bloomberg School of Public Health > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-package-devel@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-package-devel > > ______________________________________________ > R-package-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-package-devel > [[alternative HTML version deleted]] ______________________________________________ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel