set_envvar: Set environment variables

Description Usage Arguments Details Value Examples

View source: R/utils.R

Description

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

Usage

1
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

1
2
3
4
vars = xfun::set_envvar(c(FOO = "1234"))
Sys.getenv("FOO")
xfun::set_envvar(vars)
Sys.getenv("FOO")

xfun documentation built on June 16, 2021, 1:07 a.m.