R Studio Can't Install Packages


R Studio and its sub programs such as Sweave may not work correctly if its default save directory has not been set up correctly. R Studio saves to the Windows working directory which may be inaccessible on SPU computers. These steps should fix any R Studio issues related to saving files or installing new packages. 

This process has two major parts, and both must be completed on each affected computer.

Changing the Default Working Directory

StepsRelevant Data and Screenshots
  1. Open R Studio

2. Go to Tools → Global Options

3. Under the option "Default working directory (when not in project)", click Browse

4. Navigate to "C:\Users\<your_username>"

5. Create a new folder called "RStudioPackages", and select it

6. Click Open, and then click Apply. This sets the working directory when not in a project.

Changing the Default Package Directory

R Studio does not provide an inbuilt way of changing the package directory. However, a system-wide modifier can be added that forces R Studio to change the package install directory. This system-wide modifier is called an environment variable. 

You will need to reinstall all previously installed packages after completing this process

StepsRelevant Data and Screenshots
  1. Go to Control Panel → User Accounts → User Accounts → Change my environment variables

2. Click "New" under user variables

3. For Variable Name, type in R_LIBS_USER
4. For Variable Value, type in the path of created RStudioPackages (From steps 4 and 5 of previous section), and click OK

5. Click OK again to exit the the Environment Variables screen. 
6. Restart R Studio

Installation Path

When installing the packages, make sure that the installation path in the installation wizard is the same as the above variable value.