Change the working directory, evaluate the expression, and restore the working directory.

in_dir(dir, expr)

Arguments

dir

Path to a directory.

expr

An R expression.

Examples

library(xfun)
in_dir(tempdir(), {
    print(getwd())
    list.files()
})
#> [1] "/tmp/Rtmpu8f7VT"
#> [1] "downlit"           "filef3787106ec815" "filef37871bb43cbb"
#> [4] "filef37876d868244"