1  Installing R and RStudio


You will have to install R and RStudio separately. R

In addition, we will need to install the following packages:

    install.packages("tidyverse")
    library(tidyverse)

When installing packages, you will have to put the package’s name into quotation marks (double or single). Otherwise, R will not be able to find and download the specific package. When loading a package, you do not have to put the name into quotation marks.

Apart from major R/ RStudio updates, you will not have to download the packages again before running your code. Once downloaded, the packages are saved to your computer. But you will have to load your packages when restarting R and running your code.

1.1 Working with R projects and R Markdown

RStudio projects provide a useful workflow for working with R. By using projects, you will have all of your files (e.g. data or scripts) accessible to your current R session. In short, R projects set the working directory.

When you start to analyse your data, create a new RProject as a first step. Making a RProject will automatically create a file with the .proj extension. Make sure to save this file together with all additional scripts in one folder. In addition, put your data into a subfolder titled “data”. This subfolder is located in the same folder as your .Rproj-file and scripts.

To initialise a new R-session, do so by opening the .Rproj-file and not by opening your R scripts. Doing so will ensure that your working directory is set up correctly.

1.1.1 RMarkdown

RMarkdown is a formatting language. It allows you to combine your code, results from your data analyses such as plots as well as written text chunks into a formatted and reproducible document. Its advantages lie in the reproducibility of your results since your code, your results from the analyses, your hypotheses, instructions, and even your conclusion can all be found in one document. In order to use RMarkdown, you will have to install the package rmarkdown.

Try to knit (= creating the document by executing the R code chunks and creating a R markdown (.md) document) the following two files: