Introduction

Installing R packages through CRAN, GitHub, and GitLab on Linux and standard Windows operating systems is usually a simple procedure. However, this can become extremely frustrating when using a Windows machine situated on a larger network with Active Directory and shared network drives containing the user’s “Documents” folder. Complications often arise due to 2 issues:

  • Windows network drives are specified with UNC paths that are not supported by R.

  • The user does not have the requisite permissions to read and write on their network share.

These scenarios are a major hinderance and commonplace in universities and other professional networks. Although many packages from CRAN will install properly under these circumstances, packages installed over Git via devtools will often fail.

In order to ensure that R users on Windows networks can utilize all packages, please follow these steps.

Setting Up a Network Package Library

Before you begin, you may want to uninstall previous versions of R and huntdown and delete your old libraries. If you’re in a similar situation as I was, you may have a mess of various libraries scattered across your network drive and local C:\Programs\R\ directories due to default R settings, trouble shooting, and running R and RStudio as an administrator. Just a word of caution; let us begin.

Although R does not support UNC paths (\\university.edu\share\username\documents) common in many universities and businesses, R does support network drives that are mapped to a drive letter. By default, most UNC network paths are already mapped to a letter (commonly U:\). If your path is not already mapped to a letter, you may do so by following the steps laid out in Microsoft’s support article for Windows 7 and Windows 10 users.

After successfully mapping your network drive, it’s adviseable to create a new directory on your network drive to store your package repository. This will ensure that you have the requisite permissions to read and write to the library folder. For this walkthrough I created the folder U:\Documents\R-Library.

Once your new directory is established you must create an environmental variable in Windows’ Control Panel to point R to your new folder as the package installation default. Begin by clicking the Start icon or pressing the Win key. Begin typing environmental variable, the dialogue window for Environmental Variables will appear after a few letters.

Figure 1: The Windows 10 Start Interface

Figure 1: The Windows 10 Start Interface

Selecting Edit the system environment variables will initiate the System Properties interface. At the bottom, click the Environment Variables... button.

Figure 2: The System Properties interface.

Figure 2: The System Properties interface.

This will bring up the Environmental Variables interface. You can see I’ve already created the new entry while testing this procedure under User variables for jbrinks. You will create a new entry for R_LIBS_USER by clicking the New... button highlighted in the screen capture.

Figure 3: The Environmental Variables interface.

Figure 3: The Environmental Variables interface.

This will bring up the new entry dialogue window.

Figure 4: Enter a new user environmental variable.

Figure 4: Enter a new user environmental variable.

The Variable name: must be set to R_LIBS_USER. The Variable value: should be set to the path for the new folder we established earlier. You must use the mapped drive letter, and you must use forward slashes (/). R does not allow back slashes.

Now you’re finished. Restart R and your new default directory should be recognized.