Skip to content

Dear Internet Explorer user: Your browser is no longer supported

Please switch to a modern browser such as Microsoft Edge, Mozilla Firefox or Google Chrome to view this website's content.

Changing the default library folder path in R

A simple procedure in Microsoft Windows for setting the default library folder for installations of R.

Installations of R will tend to install libraries at C:/Program Files/R/R-X.X.X/library, which may not always be writable. The only way to effectively change this default resides outside of R in Microsoft Windows.

In the Microsoft Control Panel, go to System and Security > System > Advanced system settings > Environment variables.

Screen capture of the environment variables panel in Microsoft Windows 10.
The environment variables panel in Microsoft Windows 10.

A new environment variable should be created by clicking on “New…” and entering R_LIBS_USER as the variable name and C:\Path\To\R-Libraries as the variable path (change as appropriate).

Save the changes and restart R. Packages should now be saved to the new location.

The PowerShell Method

Another method for achieving this in the command line is via Windows PowerShell:

[Environment]::SetEnvironmentVariable("R_LIBS_USER", "C:\Path\To\R-Libraries", "User")
   

Comments

6 responses to “Changing the default library folder path in R”

On 20 April 2019, Carina wrote: Hyperlink chain icon

Thanks a lot!! The incorrect default library issue had been bothering me and stopping me from having fun with R!

Reply

On 28 October 2019, Lars wrote: Hyperlink chain icon

Thank you! =D

Reply

On 9 May 2020, Krishna wrote: Hyperlink chain icon

This was extremely helpful, thanks! OneDrive syncs my “Documents” folder, so I wanted to move my R library out from that folder. It was easy after I read this post.

Reply

On 15 July 2020, DK Masta wrote: Hyperlink chain icon

Very helpful. I was frustrated due to onedrive being the default path. Sync was the problem.
Thanks a lot.

Reply

On 18 June 2021, Xiaoyi wrote: Hyperlink chain icon

I really appreciate your post, which helped a lot to bypass the annoying OneDrive issue. Thanks!

Reply

On 25 June 2021, Paulo wrote: Hyperlink chain icon

Hello, this tip solved a issue with the OneDrive folder that I was experiencing after R installation.
Thank you!

Reply

Have Your Say

The following HTML is permitted:
<a href="" title=""> <b> <blockquote cite=""> <code> <em> <i> <q cite=""> <strike> <strong>

Comments will be published subject to the Editorial Policy.