3  Installation & Setup

This workshop requires three things to be installed:

Most workshops on R programming make use of an RStudio server. With an RStudio server, the participant logs in onto the website and gets a web based RStudio IDE. We prefer a local installation of RStudio for our workshop. We hope that this removes a barrier for users to start working with R themselves.

Because not every system is equally cooperative in installing everything, we have compiled an elaborate troubleshooting guide. Please let us know of any errors that you encountered, and how you fixed them! We will add these to the guide.

3.1 Installation

3.1.1 Install R and RStudio on a personal laptop.

I.e. a laptop with administrator rights.

  1. Install R from https://cran.rstudio.com/
  2. Install Rstudio from https://www.rstudio.com/products/rstudio/download/#download

3.1.2 Install R and RStudio on a Utrecht University laptop.

  1. Open Software Center
  2. Install R for Windows

Installing R packages on a Utrecht University laptop can be hard. This is because R packages are installed on a so-called ‘mounted’ drive. This causes problems with the performance. Check the installation as follows:

  1. Open RStudio
  2. Write the following line of code in your console: .libPaths(), and press enter to execute.
  3. If the response starts with // or \\, you are installing on a mounted drive. Follow the steps below to change the installation location.

3.2 Install Tidyverse from Rstudio

From the console:

  1. Open Rstudio.
  2. Look for a window that says “console” (probably bottom left of your screen).
  3. In the console, type: install.packages("tidyverse").
  4. Hit ‘enter’.

You can also install using the RStudio GUI:

  1. Open Rstudio.
  2. At the window on the bottom right of your screen, select the tab “packages”.
  3. Click “install” and type “tidyverse” in the box.
  4. Make sure the checkbox marked “install dependencies” is checked, and click “install”.

The tidyverse installation might take a while, just let it run. If it asks you something, say ‘yes’, unless it looks particularly outlandish.

If you want to check your tidyverse installation, find the ‘console’ window, and type: library(tidyverse). Then hit ‘enter’.

You should see something that looks like this:

── Attaching packages ────────────────────────────────────────────────tidyverse 1.2.1 ──
✔ ggplot2 2.2.1     ✔ purrr   0.2.5
✔ tibble  1.4.2     ✔ dplyr   0.7.4
✔ tidyr   0.8.1     ✔ stringr 1.2.0
✔ readr   1.1.1     ✔ forcats 0.3.0
── Conflicts ────────────────────────────────────────────────tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag() 

3.3 Troubleshooting

3.3.1 Packages are being installed on a mounted drive

This can cause various errors, and even if everything goes right, installing tidyverse takes ages.

Solution 1:

  • There is a solution to prevent problems with mounted drives for applications like R, RStudio and Office. Read more about the solution on intranet.

Solution 2:

  • Create a folder R-packages on a local drive.
  • Copy the location to that drive. For example: C:/Users/User/R-packages.
  • Run the following line of code: file.edit(file.path("~", ".Rprofile"))
  • Paste .libPaths("C:/Users/User/R-packages") in the editor and save the file.
  • Restart your R session
  • Click on Packages>Install. Is Install to library pointing to C:/Users/User/R-packages?
  • If not: check if the path is correctly spelled. Try inverting the slashes (\ instead of /). You may need to use double slashes (\\ or //).
  • Tick ‘source on save’, click save, and check Packages>Install again.

3.3.2 Tidyverse installation is aborted

If the installation of tidyverse is aborted, and packages are downloaded but their installation is said to have “non zero exit status”, you may be dealing with an old version of R.

Update R by installing a recent version from CRAN. Then try installing tidyverse again.

Do you have Rtools installed? (Only on Windows; it is not clear why this works but it sometimes does.). Install this via cran.r-project.org/bin/windows/Rtools/.

3.3.3 “Unable to move temporary installation” (Windows error)

Do you get issues like this:

> install.packages("tibble")
Installing package into ‘C:/Users/UserName/R’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.4/tibble_1.4.2.zip'
Content type 'application/zip' length 172649 bytes (168 KB)
downloaded 168 KB

package ‘tibble’ successfully unpacked and MD5 sums checked
Warning in install.packages :
  unable to move temporary installation ‘C:\Users\UserName\R\file18b813387562\tibble’ to ‘C:\Users\UserName\R\tibble’
The downloaded binary packages are in
C:\Users\UserName\AppData\Local\Temp\RtmpYh5ogU\downloaded_packages

Check for the line unable to move temporary installation. Your virus scanner might be blocking the installation of tidyverse.

The solution (found here) is to enter:

trace(utils:::unpackPkgZip, edit=TRUE)

You should see:

Tracing function "unpackPkgZip" in package "utils (not-exported)"
[1] "unpackPkgZip"

And a file should open. Change 0.5 in line 142 to 2.5, save the file, and try installing tidyverse again.

3.3.4 Library(tidyverse) loading failed

Dependencies might be missing, or outdated, and need to be installed/updated manually. For instance, you see the following error:

Error: package or namespace load failed for 'tidyverse'in loadNamespace(...)
namespace 'bindrcpp' 0.2 is being loaded, but >= 0.2.0.9000 is required.

Run install.packages("bindrcpp")to update this package.

Error: package or namespace load failed for 'tidyverse'in loadNamespace(...)
there is no package called (xxx)

The same solution as above applies: run install.packages() to add whatever package is missing. (At the time of writing, it is not clear why these packages are missing; this error was received over email.)