End-running renv

Author

Galen Holt

I use {renv} to manage packages, but it is not uncommon for renv::restore to fail if enough time has passed. Maybe a package no longer exists. Maybe the package versions don’t work with the current R version (most common). We can use rig to downgrade R for that project, but lately that is failing with new versions of Rstudio. And sometimes we just want to install all the packages in a project, but all-new versions. If everything worked right, renv::update() should do that, but not if the packages haven’t been successfully restore()d.

We can stil use renv to solve this. Get the dependencies, make them a character vector, and install them. That’s way less work than my old method of running renv::status(), seeing what it said was missing, and installing, especially since that method included dependencies, and so had a lot of needless installs that would have happened with the outer package.

deps <- renv::dependencies()
chardeps <- unique(deps$Package)

# I really don't want to run this here, and only partially trust eval: false
# renv::install(chardeps)

Some end up failing anyway. To find out where those are used, use

deps[which(deps$Package == 'FAILEDPACKAGENAME'), ]

The failures are annoying because they don’t just fail that one, they fail everything and then we have to start over. One dumb solution that fixes this would be to loop over each package in turn, and save its name if it fails. I have code to do that, but will need to find it.