renv library doesn't work well when sharing RStudio cloud projects

Using renv to manage the package library in RStudio Cloud, the status of the library is broken when sharing the project. This is because renv uses a global package cache and the local packages are only links. When the project is shared, the new user will not have the proper package cache and thus all the links start broken.

The user experience is that if I want to share a project that uses renv in Rtudio Cloud, the recipient has to run renv::repair(), which can be confusing and take a long time. Compared with the experience of not using renv, in which required packages are come installed with the project, it's much worse, particularly for teaching and short workshops.

I raised the issue in the renv repo too and @kevinushey recommended setting the global cache to inside the project by setting the RENV_PATHS_CACHE environmental variable to renv/cache.

I haven't tested this but I guess it should work (although I don't know how well it would play with cloud's size limits!).

@kevinushey also said:

The downside to using a project-local cache, of course, is that the cache would no longer be visible in your other projects, since the cache would be bound to the project instead of your user account... so choosing the cache location requires some care here.

Ideally, the cache would be visible to:

  • The user (or users) who need to access the shared project,
  • Users who need to use the renv cache even outside of a particular shared project.

But I'm not sure if RStudio Cloud has any notion of such persistent shared storage.

So I guess:

  1. What's the best way of using renv with RStudio Cloud that's friendly with sharing projects? Is RENV_PATHS_CACHE = renv/cache the best workaround?
  2. Is there something that can be changed either in RStudio Cloud or renv (or both?) to make this work painlessly?

Hi,

Thanks for the thoughtful post. Right now, my recommendation would be to include an /cloud/project/.Renviron file in your project that sets RENV_PATHS_CACHE to a location under the /cloud/project directory. This will ensure that the renv cache gets preserved when the project is copied.

As Kevin mentioned, this directory isn't shared between projects, but it would ensure that copies of the project can be opened without having to run renv::repair().

I have filed an internal issue to see if it makes sense for us to set this environmental variable by default so all projects can benefit from this behavior. Let us know if the solution above helps or if you run into any issues while we investigate a possible global fix in the weeks ahead.

-Andy

1 Like

Thanks.

In terms of the limit in project size, my guess is that the cache would count towards that limit, right? Although I don't know if the regular user library also counts or not.

Yes. The cache will count against the project's storage limit, but this is true already when not using renv because packages are installed under /cloud/lib.

Ah, ok. Then it's the same. Thanks for the solution.

Thanks again @eliocamp for reporting this. We've basically made this the default in rstudio.cloud as of a few hours ago, except that we set RENV_PATHS_CACHE to a slightly different location. (RENV_PATHS_CACHE = renv/cache would have caused packages to be included in the export zip when you ask rstudio.cloud to export your project, which isn't current behavior.)

We'd appreciate hearing how this works for you, especially if we missed something or you run into other unexpected side-effects from this change. Thanks!

Mike

1 Like

I've just tested it and it works well. Thanks a lot!

This topic was automatically closed 7 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.