envvars: Environment Variables

envvarsR Documentation

Environment Variables

Description

Get, set, or remove environment variables.

Usage

envvars(...)

getEnvvar(x, default = NULL)

Arguments

...

environment variables to get, set, or remove. See Examples.

x

character string holding an environment variable name.

default

if the specified environment variable is not set, this value is evaluated and returned. This facilitates retrieving an environment variable and checking whether it is set and setting it separately if not.

Details

envvars provides a mechanism for getting, setting, and removing environment variables in a way more in line with options.

Invoking envvars() with no arguments returns a list with the current values of the environment variables. To access the value of a single environment variable, one should use, e.g., getEnvvar("HOME") rather than envvars("HOME") which is a list of length one.

Value

For getEnvvar, the current value set for environment variable x, or default if the option is unset.

For envvars(), a list of all set environment variables sorted by name. For envvars(name), a list of length one containing the set value, or NA if it is unset. For uses setting one or more environment variables, a list with the previous values of the environment variables changed (returned invisibly).

See Also

Environment Variables

Examples

oenv <- envvars(); utils::str(oenv)  # oenv is a named list

getEnvvar("PATH") == envvars()$PATH  # the latter is slower, needs more memory

# change the language, and save the previous value
old.env <- envvars(LANGUAGE = "nn")
old.env              # previous value
envvars("LANGUAGE")  # current value


# restore LANGUAGE back to its previous value,
# or remove it if it previously did not exist
envvars(old.env)


envvars(oenv)  # reset (all) initial environment variables
envvars("LANGAUGE")

ArcadeAntics/essentials documentation built on Nov. 7, 2024, 4:33 p.m.