Open
Description
There are an increasing number of places where we want to run R code in another session with the package installed. But installing is a relatively expensive operation, so it would be nice if we could minimise the times we do it. I suggest a with_temp_install()
that does something like this:
with_temp_install <- function(code, pkg = ".") {
dev_lib <- file.path(tempdir(), "dev-library")
if (!file.exists(dev_lib)) {
dir.create(dev_lib)
}
if (needs_install(pkg)) {
install(pkg = pkg, quick = TRUE, reload = FALSE, dependencies = FALSE)
}
withr::with_temp_libpaths(code)
}
hash <- new.env(parent = emptyenv())
needs_install <- function(pkg = ".") {
# Hash R/*.R and src/*.{c,cpp} and NAMESPACE, ...
# Compare hashes
}
(With accompanying local version too)