[R-pkg-devel] Options "reset" when options(opts)

John Muschelli mu@che|||j2 @end|ng |rom gm@||@com
Thu Jul 11 07:08:06 CEST 2024


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



More information about the R-package-devel mailing list