Temporarily change the current working directory.
with_dir(new, code)local_dir(new, .local_envir = parent.frame())with_tempdir(code, clean = TRUE)
local_dir(new, .local_envir = parent.frame())
with_tempdir(code, clean = TRUE)
[character(1)] New working directory
[character(1)]
[any] Code to execute in the temporary environment
[any]
[environment] The environment to use for scoping.
[environment]
[logical(1)] A logical indicating if the temporary directory should be deleted after use (TRUE, default) or left alone (FALSE).
[logical(1)]
TRUE
FALSE
[any] The results of the evaluation of the code argument.
code
withr for examples
withr
setwd()
# NOT RUN { getwd() with_dir(tempdir(), getwd()) # }
Run the code above in your browser using DataLab