Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I copy and entire renv based project to a new PC (which does not have internet access)?

Tags:

r

renv

I have been given access to a beefy machine on which to run a large simulation. I have developed the code in an RStudio project with renv. Renv makes a local copy of all the packages and stores versions thereof in a lock file.

The target machine (which runs Windows) does not have access to the internet. I have copied the project file, the code files, the renv folder (which includes all the local copies of the packages, the lock file, and the .RProfile file, to a folder on the target machine.

When I open the project on the target machine, the .RProfile executes source("renv/activate.R"). However, this fails to load the projects, instead giving me the following message

The following package(s) are missing their DESCRIPTION files:

... Long list of packages ... 

These may be left over from a prior, failed installation attempt.
Consider removing or re-installing these packages.

Trouble is I can't reinstall them since this machine does not have access to the internet. I could manually go through each package and download the binaries on my work machine, then transfer them over to the target machine, then install them one by one, but this seems like a very painful thing to do.

Is there a way for me to convince renv, or R itself, to just use the packages in the local renv folder?

like image 311
Chechy Levas Avatar asked Oct 14 '25 14:10

Chechy Levas


2 Answers

From the Cache section of https://rstudio.github.io/renv/articles/renv.html:

When using renv with the global package cache, the project library is instead formed as a directory of symlinks (or, on Windows, junction points) into the renv global package cache. Hence, while each renv project is isolated from other projects on your system, they can still re-use the same installed packages as required.

I think that implies trying to copy the renv folder means copying those junction points (which are something like shortcuts / symlinks), not the actual underlying folder.

It looks like you already have a solution, but another option would be to call renv::isolate() to ensure that your project doesn't link to packages within the global cache, and instead just maintains an isolated library directly.

like image 87
Kevin Ushey Avatar answered Oct 20 '25 17:10

Kevin Ushey


In the end I just wrote an small script to copy the files over.

sourceFolder = "some/path"
targetFolder = "some/other/path"
subFolders = list.files(sourceFolder)
for (i in seq_along(subFolders)) {
    subFolder = subFolders[i]
    file.copy(
        from = paste0(sourceFolder, subFolder),
        to = targetFolder,
        overwrite = TRUE,
        recursive = TRUE
    )
    paste(subFolder) |> message()
}
like image 25
Chechy Levas Avatar answered Oct 20 '25 17:10

Chechy Levas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!