Debian Codegraph @

man/env_option.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/utils.R
3 \name{env_option}
4 \alias{env_option}
5 \title{Retrieve a global option from both \code{options()} and environment variables}
6 \usage{
7 env_option(name, default = NULL)
8 }
9 \arguments{
10 \item{name}{The option name.}
11
12 \item{default}{The default value if the option is not found in \code{\link[=options]{options()}} or
13 environment variables.}
14 }
15 \value{
16 The option value.
17 }
18 \description{
19 If the option exists in \code{\link[=options]{options()}}, use its value. If not, query the
20 environment variable with the name \code{R_NAME} where \code{NAME} is the capitalized
21 option name with dots substituted by underscores. For example, for an option
22 \code{xfun.foo}, first we try \code{getOption('xfun.foo')}; if it does not exist, we
23 check the environment variable \code{R_XFUN_FOO}.
24 }
25 \details{
26 This provides two possible ways, whichever is more convenient, for users to
27 set an option. For example, global options can be set in the \link{.Rprofile}
28 file, and environment variables can be set in the \link{.Renviron} file.
29 }
30 \examples{
31 xfun::env_option("xfun.test.option") # NULL
32
33 Sys.setenv(R_XFUN_TEST_OPTION = "1234")
34 xfun::env_option("xfun.test.option") # 1234
35
36 options(xfun.test.option = TRUE)
37 xfun::env_option("xfun.test.option") # TRUE (from options())
38 options(xfun.test.option = NULL) # reset the option
39 xfun::env_option("xfun.test.option") # 1234 (from env var)
40
41 Sys.unsetenv("R_XFUN_TEST_OPTION")
42 xfun::env_option("xfun.test.option") # NULL again
43
44 xfun::env_option("xfun.test.option", FALSE) # use default
45 }