Fix the R Library Bug on Windows 10
This is a quick post about how to fix an annoying R bug on Windows 10 caused by OneDrive. Many users use OneDrive to sync their Documents folder. Unfortunately, R stores libraries in the Documents folder, and OneDrive creates sync locks that interfere with the installation and updating of packages.
The solution is to set the
R_LIBS_USER environment variable to a folder that is not synced by OneDrive. This can be done by following these steps:
- Open the Run window (Win + R)
rundll32 sysdm.cpl,EditEnvironmentVariablesand hit OK.
- Click New… under “User variables” (the top panel)
- Paste variable name
- You can use Browse Directory… to choose any folder that is not synced with OneDrive (eg.
Now that you changed your library directory, you’ll need to reinstall your libraries. You could copy them from OneDrive, but some may be damaged.
Steps 1 and 2 can be replaced by searching for some part of “Edit environment variables for the current user” in the start menu. This is easier to remember, but this guide provides the shortest path.