Skip to contents

Get a variable from, in order of priority, environment variable, .env or settings.ini, or default values. Data type can be cast to boolean or integer.

Usage

get_var(
  config = NULL,
  var_name = NULL,
  path = NULL,
  default = structure("UNDEFINED_", class = "UNDEFINED_"),
  cast = NULL
)

Arguments

config

an object returned by the init_config function. If NULL, the config will be evaluated from the path argument.

var_name

the variable of interest

path

the path from where config files are searched for. If NULL,the current directory will be considered as default.

default

a default value

cast

Either a function or a type of cast. Currently implemented options are `integer`, `boolean` or `float`.

Value

The value associated to the config variable. The type depends on the cast argument. Default is string.

Examples

config <- get_config()
get_var(config, "test", default = "yes", cast = "bool")
#> [1] TRUE