Building packages with renv

Hi Everyone,

I have a question around renv and packaging up a project into a tarball. I was trying to understand how renv played into the tarball file when packaging up a project. Does renv get added into the tarball and if so how does a global cache get accounted for inside the tarball or is renv just for project development but not included when building and packaging a project?

Many thanks for any help in understanding this topic.

Are you talking about an R package as described in "Writing R Extensions" or https://r-pkgs.org/? In that case it would make sense to read Package Development with renv • renv. While the renv lock file etc. should be checked into version control, they should not be part of the tarball that results from R CMD build.

1 Like

The main thing to be aware of is that, by default, packages in the project library (by default, within the project's renv/library folder) are symlinks to a global cache. That usually implies that if you're tarring a project using renv, those symlinks will be included as-is, and (unless the tarball is unpacked somewhere where those symlinks are still valid) those packages won't be available.

That said, renv will notify you when this occurs, and you will be prompted to call renv::restore() to restore the package from the lockfile. (In other words, if you want to create an archive of a project using renv, it's a good idea to call renv::snapshot() so that the lockfile is up-to-date and can be used to restore the project later if necessary.)