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

Skip package installation in renv::use() if packages already installed. #2044

Closed
noamross opened this issue Nov 24, 2024 · 3 comments
Closed

Comments

@noamross
Copy link

noamross commented Nov 24, 2024

I have been starting to use renv::use() for utility scripts so they self-install dependencies, like so

#!/usr/bin/env Rscript

script_version = "0.2.0"
script_lib =  tools::R_user_dir(paste0("myScript_", script_version), "data")
if (!dir.exists(script_lib)) dir.create(script_lib)

if (!requireNamespace("renv", quietly = TRUE)) {
    install.packages("renv")
}

options(repos = c(rOpenSci = "https://ropensci.r-universe.dev", getOption("repos")))

renv::use(
  "docopt@0.7.0",
  "rnaturalearthhires",
  verbose = TRUE,
  sandbox = FALSE,
  library = script_lib
)

library(docopt)
library(rnaturalearthhires)

sessionInfo()

The idea is that the script has a self-contained library and is portable across machines without interfering with the user library (analagous to uv tool run). However, I note that renv::use() always installs the packages, even if they are already in the library. This is fast when using the renv package cache, but still adds startup overhead. Would it be possible for use() to skip installation if the correct package version exists in the library directory already?

@kevinushey
Copy link
Collaborator

Thanks for the feature request -- I can take a look.

@kevinushey
Copy link
Collaborator

Thanks! I've implemented something in 1093f0f; can you let me know if that seems sufficient?

@noamross
Copy link
Author

noamross commented Dec 6, 2024

Looks like it! Network calls are avoided, and the total time of renv::use() was consistently cut down from ~0.016s to ~0.008s. Thanks.

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

No branches or pull requests

2 participants