rstudio / renv

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

renv::status() shold not give "out-of-sync" warning when additional packages have been captured with renv::snapshot(type = "all") #1231

Open eastclintw00d opened 1 year ago

eastclintw00d commented 1 year ago

In my project it is sometimes necessary to capture more packages in the renv.lock than I currently use in my existing scripts. For example, when I already know that I will use additional packages in the near future. For this I use renv::snapshot(type = "all").

In renv::status() I get a warning that the project is out-of-sync. In my opinion this unnecessary, at least at start-up. The check should rather be if all packages versions match the lock file.

hadley commented 1 year ago

Can you please include the message that you are seeing?

eastclintw00d commented 1 year ago

This is the message after restarting R:

Restarting R session...

* Project '~/my-project' loaded. [renv 0.17.3]
Registered S3 method overwritten by 'quantmod':
  method            from
  as.zoo.data.frame zoo 
Loading required package: RPostgres
* The project is currently out-of-sync.
* Use `renv::status()` for more details.

But renv::status() only returns packages that are installed and recorded in renv.lock but are currently not used. Of that I am already aware because I accepted this by calling renv::snapshot(type = "all") and I would prefer not being notified after every session restart. I would rather get notified if anything deviates from the renv.lock file.

Here is the output of renv::status():

> renv::status()
The following packages are recorded in the lockfile, but do not appear to be used in this project:
                  _
  KernSmooth        [2.23-20]
  boot              [1.3-28.1]
  brew              [1.0-8]
  class             [7.3-21]
  cluster           [2.1.4]
  codetools         [0.2-19]
  credentials       [1.3.2]
  devtools          [2.4.5]
  downlit           [0.4.2]
  foreign           [0.8-84]
  gert              [1.9.2]
  gh                [1.4.0]
  gitcreds          [0.1.2]
  httr2             [0.2.2]
  ini               [0.3.1]
  miniUI            [0.1.1.1]
  nnet              [7.3-18]
  pkgbuild          [1.4.0]
  pkgdown           [2.0.7]
  profvis           [0.3.7]
  rcmdcheck         [1.4.0]
  reactablefmtr     [2.0.0]
  remotes           [2.4.2]
  rhandsontable     [0.3.8]
  roxygen2          [7.2.3]
  rpart             [4.1.19]
  rversions         [2.1.2]
  sessioninfo       [1.2.2]
  shinyBS           [0.61.1]
  shinycssloaders   [1.0.0]
  shinydashboard    [0.7.2]
  spatial           [7.3-16]
  survival          [3.5-5]
  tippy             [0.1.0]
  urlchecker        [1.0.1]
  usethis           [2.1.6]
  webshot           [0.5.4]
  whisker           [0.4.1]
  xopen             [1.0.0]
  zip               [2.3.0]

Use `renv::snapshot()` if you'd like to remove these packages from the lockfile.
hadley commented 1 year ago

Do you still see the same problem if you register "all" as the default snapshot type?

renv::settings$snapshot.type("all")
eastclintw00d commented 1 year ago

No. The out-of-sync notification does not appear if I set the snapshot default to "all". I guess it working as intended then.

Closing this issue.

torbjorn commented 4 months ago

Hope its ok if I reopen this.

I typically don't use snapshot type as a permanent thing. Sometimes I have added a bunch of packages and want them all in the lock file. Other times I have temporarily installed packages that I dont really want in the lock file, but might still find it useful to do an implicit snapshot.

In general I find type="all" a default I do not want, and hence a config setting I do not want to set, for the fear of eventually loosing control of my library (not to say the lock file doesnt need pruning every now and then)

In another issue I mentiong ggplot2/svglite , how ggsave lets you save svg files if you have svglite installed. Though this is not a dependency. So the moment I have type="implicit" in my config (the default), renv::status() will now forever report the repo is out of sync due to the precence of svglite. And thus status() for most intents and purposes has lost all value.

(Yes, I could library(svglite) in a single file somewhere, which admitadly isnt that much of a hazzle)

But could renv::status() instead be configured on a project level to ignore extra installed packages as a default? at least the startup renv::status?. I dont like having to tell new users to ignore the out of sync warning. They will now ignore it also when it is something they should have picked up.

kevinushey commented 4 months ago

@torbjorn, at least for that specific issue, I'd like to see if it's possible for renv to detect if svglite would be required in a particular project. I suspect we could analyze calls to ggsave() and see if device = "svg" or if the path has a .svg extension? This could fail if such paths are just stored as variables, though, since the static analysis machinery isn't that smart.