Skip to content
R for the Rest of Us Logo

How to Set Your Default Package Install Location in R

David Keyes David Keyes
September 14th, 2021

One problem that people often have, especially when they work on Windows network drives, is that they can't install packages. This typically happens because they don't have admin rights on their computer and by default R tries to install packages into a location that requires admin rights.

To see where your packages are installed to by default, type .libPaths() in the console and hit enter. If you use a Windows network drive, you may see something like this:

#  [1] "\\\2K08DC1ARCPV/david.keyes/Documents/R/win-library/4.1 
#  [2] "C:/Program Files/R/R-4.1.1/library"

This shows two paths:

  1. The first points to a place on your network drive where R tries to install packages.

  2. The second points to a location in your Program Files directory.

I'm not 100% certain on these two paths, but based on my reading of StackOverflow thread I believe the first path is where packages will be installed for a non-admin user and the second is where packages will be installed for a user with admin rights.

There are two problems here:

  1. For the first path, it is not valid because it uses backslashes, which R can’t deal with.

  2. For the second path, you can only write here if you have admin rights.

Many users get stuck installing packages because the place where they, as a non-admin user, try to install packages isn't valid and they can't install into the Program Files directory. To get around this, we need to do the following:

  1. Create a directory where R should install packages.

  2. Tell R to install packages in this location.

I've created a video to walk you through the process of updating your default package installation location.

Let us know what you think by adding a comment below.

You need to be signed-in to comment on this post. Login.