Skip to content
New issue

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

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

Already on GitHub? # to your account

renv::update() not using correct library #2108

Closed
barnesparker opened this issue Mar 6, 2025 · 2 comments
Closed

renv::update() not using correct library #2108

barnesparker opened this issue Mar 6, 2025 · 2 comments

Comments

@barnesparker
Copy link

I could be misunderstanding how the code works, but the library path created here:

renv/R/update.R

Line 268 in e641696

library <- nth(libpaths, 1L)

is never actually used later in the function.

The reason I bring this up is that I'm running into a situation where I run renv::update() and it attempts to update all packages installed in my global library instead of just my project library. It has to do with what is returned by .libPaths(), which always returns a vector of size 2 - the project library and the global library path, no matter what I do (I've tried manually setting it).

[1] "~/R/apps/my_app/renv/library/R-4.3/x86_64-pc-linux-gnu"
[2] "/opt/R/4.3.3/lib/R/library" 

However, it seems like the issue I described would be irrelevant if the line I referenced above was what was used later on in the function instead of libpaths. Because the nth(libpaths, 1) would return the project library instead of both

@kevinushey
Copy link
Collaborator

Thanks for the bug report. I think this behavior is expected... for example, if I use renv::update() in a "fresh" project initialized via renv::init(), I see (using R 4.4.2 on macOS):

> renv::update()
- Checking for updated packages ... Done!
The following package(s) will be updated:

# CRAN -----------------------------------------------------------------------
- class        [7.3-22 -> 7.3-23]
- cluster      [2.1.6 -> 2.1.8]
- foreign      [0.8-87 -> 0.8-88]
- KernSmooth   [2.23-24 -> 2.23-26]
- MASS         [7.3-61 -> 7.3-65]
- Matrix       [1.7-1 -> 1.7-2]
- nlme         [3.1-166 -> 3.1-167]
- nnet         [7.3-19 -> 7.3-20]
- rpart        [4.1.23 -> 4.1.24]
- spatial      [7.3-17 -> 7.3-18]
- survival     [3.7-0 -> 3.8-3]

Do you want to proceed? [Y/n]: 
# Downloading packages -------------------------------------------------------
- Downloading KernSmooth from CRAN ...          OK [101.5 Kb in 0.45s]
- Downloading MASS from CRAN ...                OK [1.1 Mb in 0.28s]
- Downloading Matrix from CRAN ...              OK [5.9 Mb in 0.33s]
- Downloading class from CRAN ...               OK [95 Kb in 0.16s]
- Downloading cluster from CRAN ...             OK [602.8 Kb in 0.46s]
- Downloading foreign from CRAN ...             OK [334.1 Kb in 0.49s]
- Downloading nlme from CRAN ...                OK [2.3 Mb in 0.27s]
- Downloading nnet from CRAN ...                OK [122.2 Kb in 0.17s]
- Downloading rpart from CRAN ...               OK [720.5 Kb in 0.24s]
- Downloading spatial from CRAN ...             OK [152.7 Kb in 0.26s]
- Downloading survival from CRAN ...            OK [8.4 Mb in 0.84s]
Successfully downloaded 11 packages in 5 seconds.

The following package(s) will be installed:
- class      [7.3-23]
- cluster    [2.1.8]
- foreign    [0.8-88]
- KernSmooth [2.23-26]
- MASS       [7.3-65]
- Matrix     [1.7-2]
- nlme       [3.1-167]
- nnet       [7.3-20]
- rpart      [4.1.24]
- spatial    [7.3-18]
- survival   [3.8-3]
These packages will be installed into "~/scratch/matrix-example/renv/library/macos/R-4.4/aarch64-apple-darwin20".

Do you want to proceed? [Y/n]: 
# Installing packages --------------------------------------------------------
- Installing KernSmooth ...                     OK [installed binary and cached in 0.14s]
- Installing MASS ...                           OK [installed binary and cached in 0.27s]
- Installing Matrix ...                         OK [installed binary and cached in 0.19s]
- Installing class ...                          OK [installed binary and cached]
- Installing cluster ...                        OK [installed binary and cached]
- Installing foreign ...                        OK [installed binary and cached]
- Installing nlme ...                           OK [installed binary and cached in 0.1s]
- Installing nnet ...                           OK [installed binary and cached]
- Installing rpart ...                          OK [installed binary and cached]
- Installing spatial ...                        OK [installed binary and cached]
- Installing survival ...                       OK [installed binary and cached in 0.14s]
Successfully installed 11 packages in 1.7 seconds.
> find.package("Matrix")
[1] "/Users/kevin/scratch/matrix-example/renv/library/macos/R-4.4/aarch64-apple-darwin20/Matrix"

In other words,

  • renv looked at whether the packages in the system library were out-of-date;
  • For packages which were out-of-date, new copies were installed into the project library.

I think this is a reasonable default behavior, but the issue you note does mean that

  • renv::update(library = .libPaths()[1]) still considers other library paths for update,
  • There isn't a straightforward way of saying "ignore packages that are installed in a non-project library path".

@kevinushey
Copy link
Collaborator

We had some internal discussion and the consensus here is that having renv::update() only consider the project library by default is the better default behavior, so I've made that change. One can still use renv::update(all = TRUE) to install updated versions of all packages.

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

No branches or pull requests

2 participants