envvars | R Documentation |
Get, set, or remove environment variables.
envvars(...)
getEnvvar(x, default = NULL)
... |
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. |
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.
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).
Environment Variables
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.