Read an environment variable and if needed, assign a default value.
Source:R/utils.R
get_sys_env.Rd
Read an environment variable and if needed, assign a default value.
Arguments
- var
A character scalar: name of environment variable.
- default
A default value (different from
NULL
) when environment variable is unset (empty string).- type
A character scalar: to which R type will be the variable coerced.
- verbose
A logical scalar: if
TRUE
, be verbose. The default value is obtained fromgetOption("scdrake_verbose")
.
Value
A character scalar if the environment variable is set, default
if not, or empty character scalar when
default = NULL
and the variable is unset.
Examples
get_sys_env("PATH")
#> ℹ Using environment variable `PATH` with value "/usr/lib/rstudio-server/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" (character)
#> [1] "/usr/lib/rstudio-server/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
get_sys_env("NON_EXISTING")
#> ℹ Using environment variable `NON_EXISTING` with value "" (character)
#> [1] ""
get_sys_env("NON_EXISTING", default = "default_value")
#> ℹ Environment variable `NON_EXISTING` is not set -> using default value "default_value" (character)
#> [1] "default_value"