Copying R libraries to a USB

From Wild Green Memes for Ecological Fiends.

Inspiration for this post

A few people in my lab are headed to a workshop in Colombia next week, and due to the possibility of intermittent wi-fi, they need to load all of the workshop materials onto USB drives. They need R with certain packages on the USBs in versions compatible with both Macs and PCs, so I offered to help out by loading my Mac version of R and my packages.

Loading R onto a USB

The first step was to copy my installation of R onto the USB. To do this, I just copied R from my Applications folder onto the folder. We are not entirely sure if this will work yet to transfer R to someone else’s computer (if someone knows the answer, let me know!), but we are going to test it out shortly.

Loading R packages onto a USB

The next step was to transfer all of my R packages onto the USB. To do this, I first needed to figure out where the packages were saved on my computer. You can run the following in R to find where your packages are saved:

.libPaths()
## [1] "/Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library"

Next, I needed to figure out how to navigate to the USB in Terminal. According to this StackOverflow answer, all drives are mounted in /Volumes, so I ran the following in Terminal:

cd /Volumes
ls

From there, I was able to see USB DISK as one of the folders in /Volumes. In order to copy all of the packages from my computer onto the USB, I used cp to move everything from the folder found in .libPaths() onto the USB:

# replace the first file path with what you get from .libPaths()
cp -R /Library/Frameworks/R.framework/Versions/3.5/Resources/library/ /Volumes/USB\ DISK/R_packages/
comments powered by Disqus

Related