Generate revn.lock without installing packages

I'm using renv::restore() to setup R packages in a docker container.

I'm trying to figure out if there's a way to create the renv.lock without having to resort to manually setting up a R library and generating it with renv::snapshot()

Any thoughts would be greatly appreciated.

It's worth noting here that my goal is to create a reproducible environment. Part of creating that reproducible environment is to produce an renv.lock file in a reproducible manner.

Frankly, this is starting to recursive loop. For instance, I use a renv.lock to build my docker environment with a well controlled library, however, that renv.lock is a bit of a golden file. So, I'm trying to figure out how to create a renv.lock in a reproducible manner, but how do I generate the library to renv::snapshot() in a reproducible way?

The general idea is that renv.lock is created by capturing the current state of a user's R library paths, and so that implies the user has installed a set of packages via some means in order to be captured. (Usually, those would be packages that were current on CRAN at the time of installation, or perhaps some packages installed from separate remote sources.)

Right now, there aren't any exported tools to create an renv.lock "from scratch", but depending on what exactly you want to do you could try creating renv.lock by hand -- it is just JSON, after all.

It's worth confirming what your R package version requirements are -- do you want exactly some set of versions (as would be specified in a lockfile), or is there some other meaning for what the "right" versions are? (E.g. you always want to be current with CRAN, etc.) This could effect the overall approach.

@kevinushey Thanks for the feedback.

I totally understand this feels like I'm asking renv to do a bit more than it was originally designed to, but I feel like it's a natural extension of the docker example in the renv documentation.

The goal is to produce a consistent environment regardless when the docker container is fired up. As I mentioned before, it feels like renv.lock file copied into the container with the Dockerfile is a bit of a golden file with no clear derivation. This may be fine ... it just feels like to be in keeping with the idea of reproducible environments there should be a reproducible way of generating the renv.lock.

As I ramble though this, I guess the part that's throwing me is the hash as I'm not sure how to find that other than to generate an environment manually and capturing it with renv::snapshot().

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.