renv: How to rebuild cache and default packages

Hi

In our company we have multiple data analysis projects per month and somtimes I have to reuse code I wrote over 5 years ago. Because of that I really like the idea of "renv" and I'd like to introduce renv to my coworkers. However, I have problems setting this up and would appreciate If someone could help me with these questions:

When I called renv::init() for the first time, all my packages were copied in local cache. However, the cache should be the same for all users, so I set RENV_PATHS_CACHE to a path. Unfortunately everytime I install a package its getting downloaded again. I reinstalled R, Rstudio and all packages but the cache does not rebuild itself. Is it somehow possible to rebuild the cache manually?

For every new project I have to "install" all packages I use. Is it possible to set some packages as "default" when doing renv::init() so I don't habe to "reinstall" the most used packages for every new project?

It is documented, that the cache should be on the same volume as the project. What is the reason for this? Our projects are on a networkdrive. But if I set the cache to that drive then every package has to be loaded over the network.

You may also want to set RENV_PATHS_CACHE so that the global package cache can be stored on the same volume as the projects you normally work on. This is especially important when working projects stored on a networked filesystem.

Thanks and best regards

1 Like

Can you please clarify what you mean by:

everytime I install a package its getting downloaded again

How are you installing these packages? What is the exact output you are seeing? Note that if you're changing R versions, packages will need to be downloaded again as the cache is only valid for a particular (version, OS) combination.

This isn't currently possible. You might consider filing a feature request at Issues · rstudio/renv · GitHub.

I should amend this -- this restriction no longer exists with the current version of renv.

Thanks for the helpful response. I wasn't clear enough on my first point:

The first time I called renv::init(), all my packages from .libPath were copied to a local cache. When I installed a package afterwards with install.packages("xxx"), the package was linked to the local cache and no download was necessary.

Now I did the following:

  • remove.packages("renv")
  • delete %LOCALAPPDATA%/renv
  • Sys.setenv(RENV_PATHS_CACHE = "C:/renv/cache") [the folder does not exist]
  • install.packages("renv")

If now call renv::init() I get the following output:

* "C:/Users/XXX/AppData/Local/renv" has been created.
* Initializing project ...
* Discovering package dependencies ... Done!
* Copying packages into the cache ... Done!
The following package(s) will be updated in the lockfile:

# CRAN ===============================
- renv   [* -> 0.10.0]

* Lockfile written to 'C:/Users/XXX/test/renv.lock'.
* Project 'C:/Users/XXX/test' loaded. [renv 0.10.0]

However, no packages were copied into the cache. If I install.packages("data.table"), the package gets downloaded again although it is already in my .libPath (when not in a renv project). This time, it is correctly downloaded to the custom cache and linked to the cache from within the project. My question: is it possible to rebuild the cache with the packages in the "standard" .libPath? I don't want every user to redownload all the packages they already have on their harddrive.

1 Like

This is what renv::hydrate() does -- it hydrates the cache directory based on packages found within the default user library. renv::init() normally calls that for you so it's done automatically for newly-initialized projects, but you might find it useful to call that explicitly as well.

You can also use

renv::paths$cache()

to confirm that renv is seeing and respecting the newly-set RENV_PATHS_CACHE environment variable.

renv::paths$cache()points to my custom path.

  • If I do renv::init, only libraries used in the script in the project folder are downloaded to my cache path (not copied from my .libPath) and linked to in the project folder .
  • If I do renv::hydrate() in a project folder, only the libraries used in the prject are repopulated.
  • If I do renv::hydrate() while not in a renv folder, R hangs until I press "stop"in RStudio.

I'd like to have the default behaviour but with a custom cache path: On first run, all libraries are copied to te cache, so when users "install" a library it only has to be linked. Is this not implmented for custom cache path?

Would you be willing to put together a minimally reproducible example and file an issue at https://github.com/rstudio/renv/issues? Thanks!

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