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

前端 未结 3 582
耶瑟儿~
耶瑟儿~ 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 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
    

提交回复
热议问题