Temporarily change the system search path.

with_path(new, code, action = "prefix")

local_path(new, action = "prefix", .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" 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, *replacing* the current path with_path(getwd(), Sys.getenv("PATH"))
#> [1] "/private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/RtmpDRXMtu/file8851788c4f0/reference:/Users/runner/.cargo/bin:/usr/local/lib/ruby/gems/2.6.0/bin:/usr/local/opt/ruby/bin:/usr/local/opt/curl/bin:/usr/local/bin:/usr/local/sbin:/Users/runner/bin:/Users/runner/.yarn/bin:/usr/local/go/bin:/Users/runner/Library/Android/sdk/tools:/Users/runner/Library/Android/sdk/platform-tools:/Users/runner/Library/Android/sdk/ndk-bundle:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/usr/bin:/bin:/usr/sbin:/sbin:/Users/runner/.dotnet/tools:/Users/runner/.ghcup/bin:/Users/runner/hostedtoolcache/stack/2.3.1/x64"
# temporarily modify the system PATH, *appending* to the current path with_path(getwd(), Sys.getenv("PATH"), "suffix")
#> [1] "/Users/runner/.cargo/bin:/usr/local/lib/ruby/gems/2.6.0/bin:/usr/local/Cellar/ruby@2.6/2.6.6_1/bin:/usr/local/Cellar/curl/7.70.0/bin:/usr/local/bin:/usr/local/sbin:/Users/runner/bin:/Users/runner/.yarn/bin:/usr/local/go/bin:/Users/runner/Library/Android/sdk/tools:/Users/runner/Library/Android/sdk/platform-tools:/Users/runner/Library/Android/sdk/ndk-bundle:/Library/Frameworks/Mono.framework/Versions/6.10.0/Commands:/usr/bin:/bin:/usr/sbin:/sbin:/Users/runner/.dotnet/tools:/Users/runner/.ghcup/bin:/Users/runner/hostedtoolcache/stack/2.3.1/x64:/private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/RtmpDRXMtu/file8851788c4f0/reference"