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

前端 未结 3 573
耶瑟儿~
耶瑟儿~ 2020-12-17 14:41

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

相关标签:
3条回答
  • 2020-12-17 14:57

    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)

    0 讨论(0)
  • 2020-12-17 15:07

    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
    
    0 讨论(0)
  • 2020-12-17 15:10

    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)
    
    0 讨论(0)
提交回复
热议问题