Temporarily change the system search path.

with_path(new, code, action = c("prefix", "suffix", "replace"))

local_path(
  new = list(),
  action = c("prefix", "suffix", "replace"),
  .local_envir = parent.frame()
)

Arguments

new

[character]
New PATH entries

code

[any]
Code to execute in the temporary environment

action

[character(1)]
Should new values "replace", "prefix" (the default) or "suffix" existing paths

.local_envir

[environment]
The environment to use for scoping.

Value

[any]
The results of the evaluation of the code argument.

See also

withr for examples

Sys.setenv()

Examples

# temporarily modify the system PATH, *prefixing* the current path
with_path(getwd(), Sys.getenv("PATH"))
#> [1] "/cluster-data/user-homes/elizabethb/projects/pkgdown-docs/prism/package-info/withr_3.0.2/docs/reference:/cluster-data/user-homes/elizabethb/.cargo/bin:/cluster-data/user-homes/elizabethb/.local/bin:/usr/local/texlive/2024/bin/x86_64-linux:/opt/python/3.12.4/bin:/opt/PsN/5.4.0/bin:/opt/julia/1.10.4/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/bin:/opt/aws/bin:/opt/parallelcluster/pyenv/versions/3.9.19/envs/awsbatch_virtualenv/bin:/opt/slurm/bin:/opt/quarto/v1.5.57/bin:/usr/lib/rstudio-server/bin/postback"
# temporarily modify the system PATH, *appending* to the current path
with_path(getwd(), Sys.getenv("PATH"), "suffix")
#> [1] "/cluster-data/user-homes/elizabethb/.cargo/bin:/cluster-data/user-homes/elizabethb/.local/bin:/usr/local/texlive/2024/bin/x86_64-linux:/opt/python/3.12.4/bin:/opt/PsN/5.4.0/bin:/opt/julia/1.10.4/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/sbin:/usr/bin:/snap/bin:/usr/bin:/opt/aws/bin:/opt/parallelcluster/pyenv/versions/3.9.19/envs/awsbatch_virtualenv/bin:/opt/slurm/bin:/opt/quarto/v1.5.57/bin:/usr/lib/rstudio-server/bin/postback:/cluster-data/user-homes/elizabethb/projects/pkgdown-docs/prism/package-info/withr_3.0.2/docs/reference"