atWithEnvVars
Temporarily Set or Unset Environment Variables

Description

Evaluate an expression whole certain environment variables are set to certain values (including not being set at all).

Usage

atWithEnvVars(envvars, expr)

Arguments

envvars A character vector with names. names(envvars) gives the names of the environment variables to set and as.vector(envvars) the values to set them to. The special value NA_character_ means to unset the variable.
expr A literal expression. It will be evaluated in the frame of the caller after the enviroment variables are set and its value returned to the caller. Before its value is returned, the environment variables names(envars) will be set to the state they were in before this function was called.
Value
The value of the the evaluated expression expr.
Examples
assertionTest::atWithEnvVars(c(R_MAKEVARS_USER=NA_character_), tools::makevars_user())
file.create(tf <- tempfile())
assertionTest::atWithEnvVars(c(R_MAKEVARS_USER=tf), tools::makevars_user())
tools::makevars_user()
file.remove(tf)
assertionTest::atWithEnvVars(c(R_MAKEVARS_USER=tf), tools::makevars_user())
Package assertionTest version 6.0.0-69
Package Index