How to fix RStudio’s package installation on Windows 10
This is a quick guide on how to solve an annoying flaw in how RStudio works on Windows 10. By default, it places user-installed packages on OneDrive. Packages are code, not data, and should be installed locally, not on a network drive. It’s frustrating that they’re on OneDrive, since that depends on internet access and slows down all operations compared to a local install.
From a quick web search, it’s annoying a lot of people. However, many of the offered solutions don’t work, or are missing key steps. The solution here works with the latest release of R 4.0.
You need to do three things:
- Create the local folder you want to use for packages.
- Give yourself permission to change your RProfile file.
- Change your RProfile file.
1. Create the local folder
To create the folder, open File Explorer → click on the C: drive (it should also say Local Disk) → click on the New Folder button on top → type a name like RFolder → press Enter.
2. Change permissions
In you installed RStudio in the default directory, the path to your RProfile file is C:\Program Files\R\R-4.0.0\library\base\R\Rprofile.
Steps (screenshot below):
- Navigate to C:\Program Files\R\R-4.0.0\library\base\.
- Double-click the base folder so that you’re looking at its contents, which include the R subfolder.
- Right-click on the R subfolder and select Properties.
- Click on the Security tab.
- Click on the Edit button.
- Scroll down the Group or user names pane and click on the Users line near the bottom of that list.
- In the Permissions for users pane click on the Full Control checkbox under Allow.
- Click OK and OK again to save and exit these windows.
3. Edit the RProfile file
Now that you have Write permissions, double-click on the R subfolder, then on the RProfile file (make sure RStudio is closed). Windows will prompt you with which program to use to open the file. Notepad is fine if you don’t use a professional text editor.
Once the file is open, back it up by saving it as RProfileBackup.txt. Close Notepad.
Double-click on RProfile to reopen it. Now that it’s backed up you can safely edit it. Scroll down until you see the following snippet:
(The above screenshot is in Sublime Text, a professional text editor, which is why it’s colorized.)
In the file.path line, delete Sys.getenv(“R_USER”) and replace it with “C:/RFolder” or whatever folder you created initially. Take care to delete and type the exact sequence of characters I’ve bolded here. Any deviation and it won’t work. Be sure to include the quotes around the folder path. Save and exit.
And that should do it. Open RStudio and try installing some packages. The popup should display the local folder you specified in your RProfile file. Now package installation, compilation, and use will be faster since it’s running off your local drive (SSD or hard drive).
Note: This is a solution for a default install of Windows 10, which uses OneDrive as your home folder, or the OneDrive Documents folder specifically. If you set up Windows 10 so that it’s not logged into a Microsoft account by default, your home folder is local and RStudio is already installing packages locally.
José Duarte is a social scientist and data scientist. You can reach him at firstname.lastname@example.org.