Skip to content

Instantly share code, notes, and snippets.

@vankesteren
Last active July 26, 2018 07:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vankesteren/f2e198aa5ab4f6262b21a3d13bbea0b5 to your computer and use it in GitHub Desktop.
Save vankesteren/f2e198aa5ab4f6262b21a3d13bbea0b5 to your computer and use it in GitHub Desktop.
A tutorial for UU employees to install `R` and `RStudio` locally.

Setting up R and RStudio on your work laptop

R and Rstudio may be slow. This is because our laptops install to the network by default. When you intend to work with these programs regularly, you will be unhappy with that situation.

Here's a step-by step tutorial to installing R the right way. Administrator rights required.

  1. Try to uninstall R and RStudio. This may be impossible, but try anyway.

  2. Download R. When the .exe is downloaded, right-click it and "run as administrator". Make sure it installs on your C:\ drive.

  3. Download RStudio. Again, right-click and "run as administrator" to install it on your C:\ drive.

  4. Go to the installed rstudio.exe (for example by pressing the windows key and typing rstudio). Right-click it > properties > compatibility > check "Run this program as an administrator" > apply. This is required to install packages on the C:\ drive.

  5. Make a folder on your C:\ drive where you want R and RStudio to go by default. For example C:\Users\<username>\r_dir.

  6. Press the windows key, type "environment" and open "Edit the system environment variables".

  7. Click on "Environment Variables..." this opens another dialog. Here we will add 2 entries in the User variables and in the system variables. For each of these, click "New"

    • Variable name: R_HOME; Variable value: C:\Program Files\R\R-[x.x.x] (the folder you installed R to)
    • Variable name: R_USER; Variable value: C:\Users\<username>\r_dir (the folder you just made)

    Environment variables done!

  8. Open the RStudio version you just installed. It will ask for administrator permission. Give this permission.

  9. Open the file C:\Program Files\R\R-[x.x.x]\etc\Rprofile.site. Add the following line:

    .libPaths("C:\\Program Files\\R\\R-[x.x.x]\\library")

    NB: replace [x.x.x] with your R version, for example 3.4.3. Close the file.

  10. Restart RStudio. Run the following 2 commands to check whether it worked:

    • .libPaths() This should return the library path on the local disk only.
    • path.expand("~") This should point to the R_USER path on your C:\ drive.
  11. Install your packages and rejoice!

Leave a comment if you have any questions.

@SjoerdGlaser
Copy link

If I install a new version of R, do I only have to redo stop 8? Or do I have to do anything else again as well?

@vankesteren
Copy link
Author

Oh hey, good question! Indeed you would only need to redo step 1 and 8 (and I suggest 9 and 10 as well 👍).

@HansLandsheer
Copy link

Works great. Thanks.

Small addition: For step 8 you also need administrator rights.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment