rstudio / renv

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

feature request for implicit snapshot: allow a list packages to include in addition to automatic dependencies #1930

Open torbjorn opened 3 months ago

torbjorn commented 3 months ago

renv::snapshot() defaults to type="implicit"

This misses optional dependencies of my packages that are not listed.

One example is ggsave(...) with svglite. Using ggsave to save svg files is a fairly common use case (with us at least) However svglite is not a formal dependency of ggplot2. ggsave() just warns you that you cannot save svg files unless svgite is installed.

At this point this project can no longer use renv::snapshot(type="implicit") (ie the default snapshoting behavoiur). This will remove svglite. (Yes, I could just add it manually after the snapshot, and record it, but thats not how life is supposed to be).

Would it be possible to maintain a list of packages to include in addition to dependencies found by renv? (auto dependencies is, in my belief, still a nice feature to have access to. and its the default behaviour of much of renv after all)

Ideally this file could be DESCRIPTION, but I find that whenever I try to use a DESCRIPTION file in a project that is not an R package, I get other headaches.

kevinushey commented 3 months ago

The general escape hatch for these scenarios is to create a final called deps.R (or whatever name you prefer) and add things like library(svglite) so that renv can pick those dependencies up.

Alternatively, if this is something that renv could infer via static analysis, we could also infer a dependency on svglite if we certain types of ggsave() calls.

torbjorn commented 3 months ago

An R source file deps.R whos sole purpose is to fix a deficiency/weakness elsewhere, sounds like something that should be a stop gap measure at best. Manually maintaining a list of known unspecified dependencies (like ggplot/svglite) also feels like something that will never scale well.

How about taking a stab at the source of the problem, the shortcomings of scanning source code for dependencies.

Currently package dependencies are controlled through two possible routes if I understand correctly:

How about introducing something analogous to the pyproject.toml file for poetry or requirements.txt?

So a third options could be just that:

kevinushey commented 3 months ago

https://github.com/rstudio/renv/commit/449d41f7539bf751c0d2019b43451908a4245dab could potentially help, assuming you're using "simple" calls of the form:

ggplot2::ggsave(filename = "path.svg")

with the file path used directly as a string in the call.

torbjorn commented 3 months ago

This would go some way to improving the automatic dependencies, but why not also introduce a formal way for developers to list their dependencies? The above can never be perfect and as the project grows chances are it will dyncamically create filenames and auto-depencies are out the window again.