Skip to content

Commit

Permalink
avoid reinstalling packages in use (#2044)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinushey committed Dec 6, 2024
1 parent b990d1d commit 1093f0f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

# renv 1.1.0 (UNRELEASED)

* `renv::use()` no longer re-installs packages which are already installed
and compatible with the requested packages. (#2044)

* Fixed an issue where `renv::init()` could fail when using named remotes
in a DESCRIPTION file's `Remotes:` field. (#2055)

Expand Down
32 changes: 27 additions & 5 deletions R/use.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,40 @@ use <- function(...,
return(invisible())

# resolve the provided remotes
remotes <- lapply(dots, renv_remotes_resolve)
names(remotes) <- map_chr(remotes, `[[`, "Package")

records <- lapply(dots, renv_remotes_resolve, latest = TRUE)
names(records) <- map_chr(records, `[[`, "Package")

# remove any remotes which already appear to be installed
compat <- enum_lgl(records, function(package, record) {

# check if the package is installed
if (!renv_package_installed(package, lib.loc = library))
return(FALSE)

# check if the installed package is compatible
record <- resolve(record)
current <- renv_snapshot_description(package = package)
diff <- renv_lockfile_diff_record(record, current)

# a null diff implies the two records are compatible
is.null(diff)

})

# drop the already-installed compatible records
records <- records[!compat]
if (empty(records))
return(invisible())

# install packages
records <- local({
renv_scope_options(renv.verbose = verbose)
install(packages = remotes, library = library, prompt = FALSE)
install(packages = records, library = library, rebuild = character(), prompt = FALSE)
})

# automatically load the requested remotes
if (attach) {
enumerate(remotes, function(package, remote) {
enumerate(records, function(package, remote) {
library(package, character.only = TRUE)
})
}
Expand Down

0 comments on commit 1093f0f

Please sign in to comment.