options()
and environment variablesR/utils.R
env_option.Rd
If 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
.
env_option(name, default = NULL)
The option name.
The default value if the option is not found in options()
or
environment variables.
The option value.
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.
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