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/Rtmp20NGql"
#> [1] "downlit"           "file8e0811670054"  "file8e0815fd11d07"
#> [4] "file8e081767c9fa0"