Version-independent renv (to play nice with docker image)?

I've got a fairly hefty shiny app that I'm wrapping in a docker container for deployment. To save myself the agony of waiting for all the spatial packages to build, I've based my container on rocker/geospatial. This has solved most of my problems, but there are still a whole mess of packages that have specific versions pegged by renv in the lockfile that don't necessarily match the versions in the base docker image, and thus are still being downloaded on renv::restore(). Is there some way to get renv to accept any package that's already installed, even if the versions don't match the ones in the lockfile? Or do I need to figure out which versions of the packages are in the docker image and set my lockfile to use those specific ones? (I can see this potentially being an issue as newer versions of the docker image are released down the line).

Is this just not the way renv is supposed to work? I'm grateful for any insight. Thanks!

I'll take the silence as confirmation that renv is not designed to do this, I guess. I went and manually installed the same package versions as are included in the rocker/geospatial image, which will work fine until a new version of that image is released.

Sorry for taking so long to follow up; I've been out of office for a while.

I believe you could accomplish what you want with a little extra work. renv::restore() accepts a packages argument; you could supply the names of only the packages that aren't currently installed and request renv install or restore those packages specifically.

That said, you may run into issues if you find that the package requirements of the currently-installed packages differ from those requested in the lockfile.

Finally, renv maintains installed packages in a global package cache. If you had a way of sharing that cache between different Docker containers (e.g. via a mounted volume) that could also solve the issue you're seeing. Using renv with Docker • renv may be useful.

Thanks. I hadn't thought of that. I'll play around with these suggestions.