Inspecting Option Values
Usage
opt(x, default, env = parent.frame())
opt_source(x, env = parent.frame())
opts(xs = NULL, env = parent.frame())
Arguments
- x, xs
An option name or vector of option names
- default
A default value if the option is not set
- env
An environment, namespace or package name to pull options from
Value
For opt()
and opts()
; the result of the option (or a list of
results), either the value from a global option, the result of processing
the environment variable or the default value, depending on which of the
alternative sources are defined.
For opt_source()
; the source that is used for a specific option,
one of "option"
, "envir"
or "default"
.
Functions
opt()
: Retrieve an optionopt_source()
: Determine source of option value. Primarily used for diagnosing options behaviors.opts()
: Retrieve multiple options. When no names are provided, return a list containing all options from a given environment.
Examples
define_options("Whether execution should emit console output", quiet = FALSE)
#>
#> quiet = FALSE
#>
#> Whether execution should emit console output
#>
#> option : globalenv.quiet
#> envvar : R_GLOBALENV_QUIET (evaluated if possible, raw string otherwise)
#> *default : FALSE
#>
opt("quiet")
#> [1] FALSE
define_options("Whether execution should emit console output", quiet = FALSE)
#>
#> quiet = FALSE
#>
#> Whether execution should emit console output
#>
#> option : globalenv.quiet
#> envvar : R_GLOBALENV_QUIET (evaluated if possible, raw string otherwise)
#> *default : FALSE
#>
opt_source("quiet")
#> [1] "default"
Sys.setenv(R_GLOBALENV_QUIET = TRUE)
opt_source("quiet")
#> [1] "envir"
options(globalenv.quiet = FALSE)
opt_source("quiet")
#> [1] "option"