env_option | R Documentation |
options()
and environment variablesIf 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)
name |
The option name. |
default |
The default value if the option is not found in |
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.
The option value.
xfun::env_option("xfun.test.option") # NULL
Sys.setenv(R_XFUN_TEST_OPTION = "1234")
xfun::env_option("xfun.test.option") # 1234
options(xfun.test.option = TRUE)
xfun::env_option("xfun.test.option") # TRUE (from options())
options(xfun.test.option = NULL) # reset the option
xfun::env_option("xfun.test.option") # 1234 (from env var)
Sys.unsetenv("R_XFUN_TEST_OPTION")
xfun::env_option("xfun.test.option") # NULL again
xfun::env_option("xfun.test.option", FALSE) # use default
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.