Search code examples
rdependenciesr-packagerenv

renv keeps telling that packages are not used while they are


I am using renv to make my project reproducible.

However, I have two packages needed that were not automatically taken in account when using renv::snapshot() (the rnaturalearthdata and gifski packages which are 2 dependencies of rnaturalearth and knitr packages I think).

Thus, I had to manually save them using renv::record(<package>@<version>)

The problem is now, when I use renv::status(), I have the following:

The following package(s) are no longer used in this project:
                    _
  gifski              [0.8.6]
  rnaturalearthdata   [0.1.0]

Use `renv::snapshot()` to remove them from the lockfile.

(which is normal because I don't call those packages directly in my project using library(), but they are automatically imported from their dependencies)

Is there a way to tell renv that it can consider them as necessary? Because the next time I use renv::snapshot() to add other packages, I don't want those 2 packages to be erased.


Solution

  • The issue here is that these are likely Suggests dependencies, and so are not automatically snapshotted by renv -- by default, it only includes "hard" dependencies; that is, packages which are part of Imports, Depends or LinkingTo.

    The fix here is simple, though: create a file called deps.R with the contents:

    library(gifski)
    library(rnaturalearthdata)
    

    to help instruct renv that these packages should be treated as hard dependencies.

    See also the FAQ for more details.