How do I reset all options() arguments to their default values?

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)


Simply run this:

default_opts <- callr::r(function(){options()}); options(default_opts)

How it works

It works by starting a separate background process, accessing the default options within that session, and supplying the options back to the current session.

Example

# 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)

Tags:

Settings

R