Sys.getenv(x = NULL, unset = "", names = NA)
| x |
a vector of character strings giving the names of the environment
variables whose values are sought.
In UNIX, by convention, environment variable names are specified using upper-case letters. In Windows, environment variable names are case-insensitive. If x is missing, the entire environment is returned. |
| unset | a character string. Displayed when the request contains an environment name that is not set. By default, "". |
| names |
a logical value or NA.
|
Sys.getenv("HOME")
Sys.getenv("S_PRINT_ORIENTATION") # might return "landscape" (on Unix)
shome <- "SHOME"
# returns character string of the home directory
Sys.getenv(shome)
all.env <- Sys.getenv() # whole environment
leading.S <- grep("^S", names(all.env))
# index into all.env for those names starting with 'S'
all.env[leading.S]
# values of these variables; names are preserved
Sys.getenv(c("SHOME", "S_FIRST"))
Sys.getenv()[c("SHOME", "S_FIRST")]
Sys.getenv("a", unset = "not set")
#
# "not set"
Sys.getenv(names = FALSE) # list all environment variables without names.
Sys.getenv("HOME") # no names attribute
Sys.getenv(c("HOME", "FOO")) # with names attribute