As noted in the title, I\'m trying to understand how to reset all arguments in options()
to their default settings. I searched online and in the ?options
If you restart your R session, it will reset the options to the default values.
Options are saved in a list, and calling options()
will show that list.
You can save the default options after restarting R:
backup_options <- options()
You can make any changes you need, and then to revert to the default options:
options(backup_options)
Here is a handy way of resetting options with minimal fiddling:
default_opts <- callr::r(function(){options()}); options(default_opts)
It works by starting a separate background process, accessing the default options within that session, and supplying the options back to the current session.
Here is an example to show that it worked:
# Default option
options("scipen")
# $scipen
# [1] 0
# Set to something else
options(scipen = 999)
# $scipen
# [1] 999
# Reset to defaults:
default_opts <- callr::r(function(){options()}); options(default_opts)
# Option is back to its default value
options("scipen")
# $scipen
# [1] 0
I never tried it myself, but the settings package seems to provide a possibility to restore the default values without previously storing them:
library(settings)
reset(options)