Sys.getenv {base}R Documentation

Get Environment Variables


Sys.getenv obtains the values of the environment variables.


Sys.getenv(x = NULL, unset = "")


x a character vector, or NULL.
unset a character string.


Both arguments will be coerced to character if necessary.

Setting unset = NA will enable unset variables and those set to the value "" to be distinguished, if the OS does.


A vector of the same length as x, with the variable names as its names attribute. Each element holds the value of the environment variable named by the corresponding component of x (or the value of unset if no environment variable with that name was found).
On most platforms Sys.getenv() will return a named vector giving the values of all the environment variables, collated in the current locale. (It may be confused by names containing "=" which some platforms allow but POSIX does not.)

See Also

Sys.putenv, Sys.getlocale for the locale “environment”, getwd for the working directory.


## whether HOST is set will be shell-dependent e.g. Solaris' csh does not.
Sys.getenv(c("R_HOME", "R_PAPERSIZE", "R_PRINTCMD", "HOST"))

names(s <- Sys.getenv()) # all settings (the values could be very long)

## Language and Locale settings -- but rather use Sys.getlocale()
s[grep("^L(C|ANG)", names(s))]

[Package base version 2.5.0 Index]