ID EN
Environment & Scope

Sys.setenv

R Base 3.6.2

Sys.setenv sets environment variables (for other processes called from within R or future calls to Sys.getenv from this R process). Sys.unsetenv removes environment variables.

Syntax

R
Sys.setenv(&#8230;)<p></p><p>Sys.unsetenv(x)</p>

Arguments

Parameter Description
&#8230; named arguments with values coercible to a character string.
x a character vector, or an object coercible to character.

Return Value

A logical vector, with elements being true if (un)setting the corresponding variable succeeded. (For Sys.unsetenv this includes attempting to remove a non-existent variable.)

Details

Non-standard R names must be quoted in Sys.setenv: see the examples. Most platforms (and POSIX) do not allow names containing "=". Windows does, but the facilities provided by R may not handle these correctly so they should be avoided. Most platforms allow setting an environment variable to "", but Windows does not, and there Sys.setenv(FOO = "") unsets FOO. There may be system-specific limits on the maximum length of the values of individual environment variables or of all environment variables. Windows has a limit of 32,767 characters on the environment block, and cmd.exe has a limit of 2047 (Windows 2000) or 8192 characters (XP and later) for each value.

Examples

Example
R
# NOT RUN {
print(Sys.setenv(R_TEST = "testit", "A+C" = 123))  # `A+C` could also be used
Sys.getenv("R_TEST")
Sys.unsetenv("R_TEST")
Sys.unsetenv("R_TEST")  # may warn and not succeed
Sys.getenv("R_TEST", unset = NA)
# }

See Also

Sys.getenv Startup for ways to set environment variables for the R session. setwd for the working directory.The help for ‘environment variables’ lists many of the environment variables used by R.