envvar_get {envvar}R Documentation

Get the value of an environment variable

Description

envvar_get() returns the value of an environment variable.

envvar_get_oneof() gets the value of an environment variable and ensures that it is within a defined set of potential values.

Usage

envvar_get(
  x,
  default = NULL,
  transform = NULL,
  validate = NULL,
  warn_default = TRUE
)

envvar_get_oneof(
  x,
  choices,
  default = NULL,
  transform = NULL,
  validate = NULL,
  warn_default = TRUE
)

Arguments

x

String containing an environment variable name

default

Optional default value if the environment variable is not set

transform

Optional function that applies a transformation to the variable's value

validate

Optional function that checks a value for validity

warn_default

Show a warning if the default value is used (default: TRUE)

choices

A list containing the potential values

Details

envvar_get() and the other type-specific variants follow this workflow:

Value

The value of the given environment variable, if set. This is a string unless a transform function has changed the object's type.

Examples

# Get the current user's home directory
envvar_get("HOME")

# Get the current logging level for your app, ensuring it is a known value
envvar_set("LOG_LEVEL" = "DEBUG")
envvar_get_oneof(
  "LOG_LEVEL",
  choices = c("TRACE", "DEBUG", "INFO", "SUCCESS", "WARN", "ERROR", "FATAL")
)

[Package envvar version 0.1.1 Index]