Changing your default library path for R packages

THE PROBLEM

A few weeks ago, I bought a new computer: the previous one died a tragic but somewhat inevitable death. The Windows Surface Pro tablet is a great little computer that lasted 6 years, but that pesky kickstand frequently overshot its resting surface… dropping the entire tablet on the ground. The first 50 or so times this happened, it was not a big deal. The last drop broke the screen, and a broken screen on a touch screen tablet can hang up the entire boot process.

I purchased a Microsoft Surface Laptop 3 with a i7 processor and 16gb of RAM running Windows 10. The set up process, like it always will be, was a series of realizations that I forgot to install something important, normally at an inconvenient time (for example, installing Zoom when I was 5 minutes late to a meeting).

During set up, I agreed to install OneDrive. I use OneDrive for a singular purpose: to sync the background between my small computer (this one) and my 5 year old ASUS that somehow is still alive. That is it. It’s just nice, when I update the background, it’s automatically updated on the other less used computer.

I did not realize that my default home folder would be this OneDrive folder. I did not realize that R’s default package library location is an automatically generated folder within your default home folder. I did not realize that OneDrive would try to backup your package files while they were actively being downloaded to this folder. These issues led to several problems.

THE SOLUTION

You want to create a R_LIBS_USER variable in your Windows: if you do not have this, the R_LIBS_USER defaults to your home directory.

Go to the Control Panel, then System -> Advanced system settings (left side) -> Environment Variables (bottom of pop-up under Advanced Tab) -> User Variables (top box). Click “New”. Input Variable Name = R_LIBS_USER. Input Variable Value = Your\Folder\Here. Click OK. Restart and rejoice. If errors continue, consider uninstalling OneDrive (I wound up doing this out of principle since I use Google Drive and Dropbox extensively).

The best solution was found here. This comment includes instructions for if you don’t have access to the control panel (which may be a bigger issue than simply where your R Packages Library is stored). Thank you Paweł Rumian for ending hours of suffering.

There are other solutions on the internet (including in more upvoted responses): many are temporary, some flat out don’t work, and others refer you to files you didn’t know you had that, during your attempt to modify your pre-existing file, you accidentally create this file, and it’s not good either. This was the one that worked for me.

Leave a comment

Design a site like this with WordPress.com
Get started