Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Confusing workflow when developing an R package, type explicit, renv::snapshot recomends snapshotting all instead #2096

Open
torbjorn opened this issue Feb 22, 2025 · 0 comments

Comments

@torbjorn
Copy link

torbjorn commented Feb 22, 2025

Based on this issue I understand that the workflow for dependency handling during package development is that you:

  1. restore() to install Imports dependencies of the package being developed.
  2. install() to install Suggests dependencies, eg. packages lige devtools, usethis and testthat.

At this point I can meaningfully work on the package whose source dir I'm in.

(btw why should the intended renv workflow have two steps for a single operation?)

However when I run renv::snapshot() in the source dir, this happens:

> renv::settings$snapshot.type()
[1] "explicit"
> renv::snapshot()
The following required packages are not installed:
- BiocManager     [required by renv]
- callr           [required by withr]
- cli             [required by renv]
- conflicted      [required by here]
- covr            [required by fs, here, renv, and 1 other]
- cpp11           [required by renv]
- crayon          [required by fs]
- DBI             [required by withr]
- devtools        [required by renv]
- gitcreds        [required by renv]
- jsonlite        [required by renv]
- jsonvalidate    [required by renv]
- knitr           [required by fs, here, renv, and 2 others]
- lifecycle       [required by rprojroot]
- miniUI          [required by renv]
- mockr           [required by rprojroot]
- modules         [required by renv]
- packrat         [required by renv]
- pak             [required by renv]
- palmerpenguins  [required by here]
- pillar          [required by fs]
- plyr            [required by here]
- R6              [required by renv]
- readr           [required by here]
- remotes         [required by renv]
- reticulate      [required by renv]
- rlang           [required by here, rprojroot, withr]
- rmarkdown       [required by fs, here, renv, and 2 others]
- RSQLite         [required by withr]
- rstudioapi      [required by renv]
- shiny           [required by renv]
- spelling        [required by fs]
- testthat        [required by fs, here, renv, and 2 others]
- tibble          [required by fs]
- uuid            [required by here, renv]
- vctrs           [required by fs]
- waldo           [required by renv]
- webfakes        [required by renv]
- yaml            [required by renv]
Consider reinstalling these packages before snapshotting the lockfile.

Do you want to proceed? [Y/n]: 
- The lockfile is already up to date.
>

My DESCRIPTION file has these dependencies:

Suggests:
    devtools,
    testthat (>= 3.0.0),
    languageserver
Imports:
    fs,
    here,
    withr

This begs some questions:

  1. Why would snapshot suggest (re)installing all these packages before snapshoting, when snapshoting isnt going to record them any way, since I'm in explicit mode?
  2. How can I even install all those packages short of mouse-drag-select copying, putting string quotes around each of them, comma separating and pasting them into a very manual renv::install call? (renv::install() does not do it)
  3. Why not limit this advice/suggestion to the Suggests field instead? That would produce actual useful advice as opposed to this list, and it would produce a list of packages that renv::install() actually installs for you.
  4. And finally a minor thing: Few, or none, of the packages listed are required by these packages, as stated. They are typically Suggested in those packages.

I'm trying to help set up meaningful workflows for colleagues with renv when developing R packages, and this is confusing. (Personally I can live with just ignoring the above as misplaced advice, but if someone had presented this as a normal worfklow to me, I would definitely have asked the meaning of all this)

On a related note, why don't renv::restore() restore the Suggests: field in DESCRIPTION? If I ever find myself needing to do renv::restore() in a source dir of an R package (which is where DESCRIPTION belongs), surely I'd be in a situation where I intend to develop this package, and I'd then need those Suggests dependencies (eg. testthat and devtools). If I just want to "try" a package without installing it, I'd run devtools::load_all() in the source dir, which would handle the dependencies for me.

In fact, when would you ever be in the source dir of an R package and need to restore only the formal package dependencies?

(This final question belongs in that other issue but I thought I wouldn't revive that old and completed issue)

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

No branches or pull requests

1 participant