Introduction

Transferring R installed packages from one computer to another is primarily useful in a situation where you are working on an offline computer that can't connect to the internet to automatically download and install R packages. This tutorial will explain one method of downloading and installing R packages and their dependencies onto a computer that has a working internet connection and transferring the packages to a computer that does not.

Procedures

Step 1 - Install Packages to an R Computer That Has Internet Access
  1. Locate an internet connected computer which has a compatible version of R version installed which you can use to download the packages to and then copy over to the offline computer. The computer operating system has to be the same as the operating system of the offline computer. For example if the offline computer is a macOS computer then you have to use an internet connected computer that is also a mac. Similarly if the offline computer is a Windows computer then the internet connected computer also needs to be a Windows computer. For R packages it is usually the case you can use a prior version of R to download packages and transfer them to an offline computer which has a newer version of R installed however this may not always be the case.
  2. Download all the R packages that you need and do some tests with sample data to make sure you have all the packages you need to perform the analysis you are needing to do on the offline computer.
Step 2 - Copy Packages To a USB Drive
  1. The first thing you need to do is determine what folder on the internet connected R computer contains the installed packages. To do this, execute the ".libPaths()" function in R. This will output the directory on the computer that contains all the R packages which you'll need to copy off the computer.
  2. Now that you know the directory that contains the R packages, copy the entire directory to a USB drive. Usually the R packages directory contains a lot of files which may take awhile to transfer off the computer. If you are using a Windows computer you can speed things up by right-clicking on the R packages directory and choosing the option Send to... | Compressed (zipped) folder. This will compress the entire folder to a single zip file that you can then transfer off the computer. If you are using a macOS computer you can do something similar by holding down the Control key on your keyboard and clicking on the folder. Then select the Compress "Library" option.

Screenshot of R Studio and Windows File Explorer apps open with R library directory highlighted

Step 3 - Copy R Packages Directory From USB Drive to the Offline Computer
  1. Insert the USB drive containing the R packages into the offline computer.
  2. Now you need to determine where to copy the R packages directory to. Start up R on the offline computer and execute the ".libPaths()" function. Note the directory returned in the results.
  3. Locate this directory on the computer and either delete it or rename it. It would be safer to rename it in case you need to restore it if something goes wrong with the packages directory copy.
  4. Copy the R packages directory from your USB drive to the parent directory of the R packages directory on the offline computer. By doing this and the previous step you are basically replacing the R packages directory of the offline computer with a copy of the R packages directory from the internet connected computer. If you had compressed the packages directory into a single zip file then you'll need to first decompress it and then you can copy the packages "Library" folder within it.
  5. At this point the R packages should be installed and ready for use on the offline computer.