On Thu, 11 Jul 2024, David Hugh-Jones wrote:
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.
Arguably, it would be nice to have a parameter like "reset", so
that one can call
options(oo, reset=TRUE)
and any options not explicitly passed by oo are set to NULL.
This way there are two modes of operation - bulk setting of subset of
options with reset=FALSE, and restoring full options set with reset=TRUE.
best
Vladimir Dergachev
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
______________________________________________
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel