Retrieve a global option from both options() and environment variables
Source: R/utils.R
env_option.RdIf the option exists in options(), use its value. If not, query the
environment variable with the name R_NAME where NAME is the capitalized
option name with dots substituted by underscores. For example, for an option
xfun.foo, first we try getOption('xfun.foo'); if it does not exist, we
check the environment variable R_XFUN_FOO.
Arguments
- name
The option name.
- default
The default value if the option is not found in
options()or environment variables.
Details
This provides two possible ways, whichever is more convenient, for users to set an option. For example, global options can be set in the .Rprofile file, and environment variables can be set in the .Renviron file.
Examples
xfun::env_option("xfun.test.option") # NULL
#> NULL
Sys.setenv(R_XFUN_TEST_OPTION = "1234")
xfun::env_option("xfun.test.option") # 1234
#> [1] "1234"
options(xfun.test.option = TRUE)
xfun::env_option("xfun.test.option") # TRUE (from options())
#> [1] TRUE
options(xfun.test.option = NULL) # reset the option
xfun::env_option("xfun.test.option") # 1234 (from env var)
#> [1] "1234"
Sys.unsetenv("R_XFUN_TEST_OPTION")
xfun::env_option("xfun.test.option") # NULL again
#> NULL
xfun::env_option("xfun.test.option", FALSE) # use default
#> [1] FALSE