Temporarily change the current working directory.

with_dir(new, code)

local_dir(new, .local_envir = parent.frame())

with_tempdir(code, clean = TRUE)

Arguments

new

[character(1)]
New working directory

code

[any]
Code to execute in the temporary environment

.local_envir

[environment]
The environment to use for scoping.

clean

[logical(1)]
A logical indicating if the temporary directory should be deleted after use (TRUE, default) or left alone (FALSE).

Value

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

See also

withr for examples

setwd()

Examples

#> [1] "/private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/RtmpDRXMtu/file8851788c4f0/reference"
with_dir(tempdir(), getwd())
#> [1] "/private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/RtmpDRXMtu"