Search code examples
rstagingrenv

R renv package creates subfolder "staging" - can these be deleted without danger?


I'm using the renv package for keeping my R projects identical across computers. I saw that within my R project folder there is a subfolder renv/staging. This folder again contains several subfolders named from 1 to XX (in my case 38). Some of these folder contain several thousand files, which causes syncing across my devices often to crash.

I assume these subfolders contain a certain stage of my R project packages and whenever I change sth. (e.g. update a package), a new folder will be created.

Question is: can I simply delete old folders and just keep the current one (which in my case is empty, though)?

The renv website unfortunately doesn't tell anything about these staging folder and subfolders.


Solution

  • These folders can be safely deleted -- renv uses these staging folders when building + installing R packages, with the intention that successfully-installed packages are moved to their final destination in the project library only after all requested packages have been successfully installed.

    This is documented partially in https://rstudio.github.io/renv/reference/config.html -- from renv.config.install.transactional:

    Perform a transactional install of packages during install and restore? When enabled, renv will first install packages into a temporary library, and later copy or move those packages back into the project library only if all packages were successfully downloaded and installed. This can be useful if you'd like to avoid mutating your project library if installation of one or more packages fails. Defaults to TRUE.

    If you aren't a fan of this behavior, you can set this in your .Rprofile:

    options(renv.config.install.transactional = FALSE)
    

    Or, in your project's .Renviron:

    RENV_CONFIG_INSTALL_TRANSACTIONAL = FALSE
    

    I'll also update the documentation to make it clear that transactional installs make use of the renv/staging/%i folder.