Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

set_envvar

Set environment variables


Description

Set environment variables from a named character vector, and return the old values of the variables, so they could be restored later.

Usage

set_envvar(vars)

Arguments

vars

A named character vector of the form c(VARIABLE = VALUE). If any value is NA, this function will try to unset the variable.

Details

The motivation of this function is that Sys.setenv() does not return the old values of the environment variables, so it is not straightforward to restore the variables later.

Value

Old values of the variables (if not set, NA).

Examples

vars = xfun::set_envvar(c(FOO = "1234"))
Sys.getenv("FOO")
xfun::set_envvar(vars)
Sys.getenv("FOO")

xfun

Miscellaneous Functions to Support Packages Maintained by 'Yihui Xie'

v0.22
MIT + file LICENSE
Authors
Yihui Xie [aut, cre, cph] (<https://orcid.org/0000-0003-0645-5666>), Wush Wu [ctb], Daijiang Li [ctb], Xianying Tan [ctb], Salim Brüggemann [ctb] (<https://orcid.org/0000-0002-5329-5987>), Christophe Dervieux [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.