envvar_get_list()
gets lists from environment variables. At
the moment, only unnamed lists are supported.
envvar_get_csv()
and envvar_get_psv()
are an easy way to
use envvar_get_list()
with comma or pipe separators.
Usage
envvar_get_list(
x,
pattern = ":",
default = NULL,
validate = NULL,
warn_default = TRUE,
...
)
envvar_get_csv(x, default = NA, validate = NULL, warn_default = TRUE)
envvar_get_psv(x, default = NA, validate = NULL, warn_default = TRUE)
Arguments
- x
String containing an environment variable name
- pattern
String specifying the pattern used to separate elements in the list.
- default
Optional default value if the environment variable is not set
- validate
Optional function that checks a value for validity
- warn_default
Show a warning if the default value is used (default:
TRUE
)- ...
Additional arguments passed to strsplit
Examples
# Get the value of `$PATH`, creating a list with elements for each directory
envvar_get_list("PATH")
#> [1] "/opt/hostedtoolcache/pandoc/3.1.11/x64"
#> [2] "/snap/bin"
#> [3] "/home/runner/.local/bin"
#> [4] "/opt/pipx_bin"
#> [5] "/home/runner/.cargo/bin"
#> [6] "/home/runner/.config/composer/vendor/bin"
#> [7] "/usr/local/.ghcup/bin"
#> [8] "/home/runner/.dotnet/tools"
#> [9] "/usr/local/sbin"
#> [10] "/usr/local/bin"
#> [11] "/usr/sbin"
#> [12] "/usr/bin"
#> [13] "/sbin"
#> [14] "/bin"
#> [15] "/usr/games"
#> [16] "/usr/local/games"
#> [17] "/snap/bin"
# Parse an list separated by `|`
envvar_set("ROOMMATES" = "nandor|laszlo|nadja|guillermo|colin")
envvar_get_psv("ROOMMATES")
#> [1] "nandor" "laszlo" "nadja" "guillermo" "colin"