Skip to content

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

@noamross

Description

@noamross

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(
  "[email protected]",
  "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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions