R doesn’t always play nice with networked storage, and typically expects that users have admin rights when installing software. Problems can arise when installing R libraries in the default user location, and sometimes when knitting documents or performing disc-intensive operations. Users who are locked out by IT restrictions should follow the steps below when installing R and RStudio.

R file locations

On Windows, R is typically installed under C:/Program Files/R/. However, if you don’t have administrative privileges on your computer, you won’t be able to write to the /Program Files/ directory.

R’s great strength is the many libraries of functions available to simplify analysis. Under Windows, the default location for user-installed libraries is in the user’s documents folder, usually something like: C:/Users/<user_name>/Documents/R/win-library/3.42

On machines managed by a corporate IT department, the Documents folder is often stored on a server to provide automatic backups, and the local copy is mirrored from that server. In these cases, default location becomes something like //server/dir1/dir2/<user_name>/MyData/My Documents/R/win-library/3.42. Alternatively, some people may configure their computers to store their document folders in a directory synced to Dropbox or another online file storage service.

Step 1: Checking for a problem

How do you know if you’ll have a problem with the Program Files location? When you try to install R to /Program Files/, the installer will tell you that you “don’t have permission to save in this location.”

What about your Documents folder? From the Windows desktop (a.k.a. the “Explorer”), open a file window, right click on your “Documents” folder in the navigation pane, select “Properties.” If the “Location:” field starts with two slashes, you’re using network storage. Below are two screenshots showing what this would look like.

Screenshot showing Properties selection in context menu Screenshot showing Properties window with networked storage

Step 2: Create a new installation location

The easiest way that I have found to install R and RStudio under Windows, when you don’t have admin privileges, is to create a new folder named “R” under your user: C:/Users/<username>/R/.

You may choose another location, but it must not be synced to network storage, and you must have administrative privileges.

Step 3: Install R

Once that folder is created, install R normally, selecting C:/Users/<username>/R/ as the installation location, instead of the default C:/Program Files/. R should automatically create a new folder under C:/Users/<username>/R/ named R-<version number>.

Do not install RStudio. We’ll do that in a moment.

Step 4: Configuring R libraries

Create a new folder under C:/Users/<username>/R/, next to R-<version number>, named “R-Library.”

Open R and run the command path.expand("~"). This will tell you what directory R is working in when it first starts up. for synced storage, this is probably going to look something like //server/dir1/dir2/<user_name>/MyData/My Documents/.

In the indicated directory, create a new text file named .RProfile. This can be done with the Notepad app, but be careful that it does not append a “.txt” extension. The file should contain the following code:

.First <- function() {
  path_to_libraries <- "C:/Users/<username>/R/R-Library" # REPLACE <username> with your user folder!
  .libPaths(c(path_to_libraries, .libPaths()))
}

R automatically runs this .First() function at the start of every R session, and the .libPaths() function call tells R to look first for your R-Library folder whenever it needs to install or access packages.

Now close R.

Step 5: Install RStudio

Install RStudio normally, selecting C:/Users/<username>/R/ as the installation location, instead of the default C:/Program Files/. RStudio will create a folder named RStudio under C:/Users/<username>/R/.

Done!

At this point, the next time you launch R or RStudio, everything should be installed and configured to run correctly, even without administrative privileges.

When installing packages, RStudio will offer you a choice of locations to install packages into; be sure to choose C:/Users/<username>/R/R-Library.

Additional reading

If you’d like to learn more about configuring R using the .RProfile file, read the following: