Debian Codegraph @

man/with_envvar.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/env.R
3 \name{with_envvar}
4 \alias{with_envvar}
5 \alias{local_envvar}
6 \title{Environment variables}
7 \usage{
8 with_envvar(new, code, action = "replace")
9
10 local_envvar(
11 .new = list(),
12 ...,
13 action = "replace",
14 .local_envir = parent.frame()
15 )
16 }
17 \arguments{
18 \item{new, .new}{\verb{[named character]}\cr New environment variables}
19
20 \item{code}{\code{[any]}\cr Code to execute in the temporary environment}
21
22 \item{action}{should new values \code{"replace"}, \code{"prefix"} or
23 \code{"suffix"} existing variables with the same name.}
24
25 \item{...}{Named arguments with new environment variables.}
26
27 \item{.local_envir}{\verb{[environment]}\cr The environment to use for scoping.}
28 }
29 \value{
30 \code{[any]}\cr The results of the evaluation of the \code{code}
31 argument.
32 }
33 \description{
34 Temporarily change system environment variables.
35 }
36 \details{
37 if \code{NA} is used those environment variables will be unset.
38 If there are any duplicated variable names only the last one is used.
39 }
40 \examples{
41 with_envvar(new = c("GITHUB_PAT" = "abcdef"), Sys.getenv("GITHUB_PAT"))
42
43 # with_envvar unsets variables after usage
44 Sys.getenv("TEMP_SECRET")
45 with_envvar(new = c("TEMP_SECRET" = "secret"), Sys.getenv("TEMP_SECRET"))
46 Sys.getenv("TEMP_SECRET")
47 }
48 \seealso{
49 \code{\link{withr}} for examples
50
51 \code{\link[=Sys.setenv]{Sys.setenv()}}
52 }