Is there any easy way to replicate R packages between two machines?
3
3
Entering edit mode
6.9 years ago
Parham ★ 1.6k

Hi,

I am wondering if there is any easy way to have same packages of an existing R on machine 1 on a newly installed R on machine 2? Or I have to go through them and install them one by one manually?

R packages replicate • 4.0k views
1
Entering edit mode
6.9 years ago

Also not sure if it helps, but using

.libPaths()

will show the folders where R packages were installed, you can then copy those folders manually

0
Entering edit mode

That looks very straightforward. So they don't need to be installed? Just if the folders are available in that path the libraries can be loaded?

0
Entering edit mode

Hi! Yes, they should work if the lib path on the other computer points to the correct directory. I've used this in one of my recent tools:

the installer was just going through package names and invoking

install.packages(..., lib = /path/to/libs)

.libPaths(/path/to/libs)

library(...)

and it worked fine

0
Entering edit mode

That's great, thanks a lot.

0
Entering edit mode
6.9 years ago

Not sure if it is worth the effort, but you could use something like Docker to share a specific environment between computers.

0
Entering edit mode

Thanks but it seems that's too complicated for me.

0
Entering edit mode
6.9 years ago

You can write a short script to use the built-in installed.packages() function to enumerate the existing packages on machine A and then use install.packages() to install those packages on machine B, remembering your friend the dependencies flag. I often run into snags when I attempt to install a binary package from a repository, only to find that the binary in bioconductor (for example) will not run on my current version of R on my particular platform. I tend to install from source for this reason. Specifying or pulling down source code would also let you be sure that you are installing the same version of each package, as you may run into trouble if you have version 2.11 on machine A and verison 2.16 on machine B.