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/Rtmph9Zlci"
#> [1] "downlit"           "file4c1561bf1a490" "file4c15634e480e8"
#> [4] "file4c15640e37e5e"