Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

with_temp_install() #2202

Open
hadley opened this issue Mar 20, 2020 · 1 comment
Open

with_temp_install() #2202

hadley opened this issue Mar 20, 2020 · 1 comment
Labels
feature a feature request or enhancement

Comments

@hadley
Copy link
Member

hadley commented Mar 20, 2020

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)

@jimhester jimhester added the feature a feature request or enhancement label Apr 3, 2020
@hadley
Copy link
Member Author

hadley commented May 21, 2022

For now, I've made a simple local_install() which will re-install every time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants