rstudio / renv

renv: Project environments for R.
https://rstudio.github.io/renv/
MIT License
1.02k stars 155 forks source link

renv::status() displaying incomplete information about inconsistencies #1788

Closed dvg-p4 closed 9 months ago

dvg-p4 commented 9 months ago

When I have some packages that are installed but not recorded, and some other packages that are installed AND recorded but an inconsistent version, renv::status() is only showing me the former and not displaying the latter.

Reprex

Create a directory with script.R:

library(data.table) 
print(data.table(foo = 1:3, bar = 4:6))

In the directory, run:

% R
> renv::init()
- Linking packages into the project library ... Done!
The following package(s) will be updated in the lockfile:

# CRAN -----------------------------------------------------------------------
- data.table   [* -> 1.14.8]
- renv         [* -> 1.0.3]

The version of R recorded in the lockfile will be updated:
- R            [* -> 4.2.3]

- Lockfile written to "~/scratchpad/renv-masking-reprex/renv.lock".
- renv activated -- please restart the R session.
[ctrl-D]
% R
> renv::install("data.table@1.14.6")
[installs]
> renv::status()

As expected:

The following package(s) are out of sync [lockfile -> library]:
# CRAN -----------------------------------------------------------------------
- data.table   [1.14.8 -> 1.14.6]
See ?renv::status() for advice on resolving these issues.

Now, edit script.R:

library(data.table)
print(data.table(foo = 1:3, bar = 4:6))
library(ggplot2)
ggplot(mpg, aes(displ, hwy, colour = class)) + geom_point()
% R
> renv::status()
The following package(s) are missing:

 package installed recorded used
 ggplot2 n         n        y   

See ?renv::status() for advice on resolving these issues.

No information is given about data.table's discrepancy anymore.

This can lead to some unexpected behavior if you run renv::restore() or renv::snapshot() in a more realistic scenario, expecting it only to affect packages listed by renv::status(). (Thankfully, those functions will prompt you with the full list of things they're about to change, so a keen eye will reveal what's going on.)

kevinushey commented 9 months ago

@dvg-p4 let me know if you're still planning to take a look

dvg-p4 commented 9 months ago

@kevinushey Updated with reprex

kevinushey commented 9 months ago

@dvg-p4 awesome, much appreciated! This should now be resolved.