Skip to contents

Read an environment variable and if needed, assign a default value.

Usage

get_sys_env(
  var,
  default = NULL,
  type = c("character", "double", "integer", "logical"),
  verbose = getOption("scdrake_verbose")
)

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 from getOption("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"