TLDR
Allowing libraries to be installed inside the OneDrive ecosystem on Windows machines is dangerous. They have to be moved. Here’s how.
Brief Background
For longstanding file sharing reasons, OneDrive often locks files to sync and this can cause random crashes and assorted errors if the R libraries are installed there. On many computers, the default library location will exist inside the OneDrive’s domain of directories to backup. Indeed, Windows has generic file locking and sharing issues for certain file types.
How to Fix the Problem
Anything in verbatim
is code for the Terminal/Command prompt or R Console.
- We need to create a directory outside of the OneDrive’s purview; something directly off of root
C:
is best. Though you need not following my naming convention, I will usemkdir C:/RLibs
. If you choose something different, that should be substituted below where I useRLibs
. This must either be done in the RStudio in Terminal in the bottom left pane or from the Windows command prompt. - Using the RStudio’s Tools > Install packages or the R Console, we will need to install
usethis
. At the console it is,install.packages("usethis")
library(usethis)
edit_r_profile()
.libPaths(c("C:\RLibs", .libPaths()))
- Restart RStudio.
Tools > Install Packages
should now default toC:\RLibs
.
Here is a short video on youtube. WARNING: it contains some slip-ups that I intentionally made so that you can see what goes wrong in the easiest places for things to get stuck.