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/RtmpRvnkQ0"
#> [1] "downlit"            "file3a0379427c9e97" "file3a037954a78b6b"
#> [4] "file3a037957ed4ec0" "file3a037967b3c73c"