```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. 

The great advantage of using RMarkdown for exercises is that you can see exactly which step produced which output. This leaves an "audit trail" of your work, including documentation explaining the steps you made. This is helpful to not only keep your own progress organized, but also to make your work reproducible for others and more transparent.

If you do not want to knit the entire document, you can run each chunk of code one by one, by highlighting the code and clicking `Run` (or pressing `Ctrl + Enter` in Windows or `command + enter` in OS X). You can see the output of the code in the console right below, inside the RStudio window.

```{r}
print("Success!")
```

### First aid

RMarkdown is its own language and if you continue using it after the course, I highly recommend reading an introduction. But here are some **first aid tips** in case you run into trouble.

If you have trouble knitting a file, for example because there is an error in your code, you can deactivate the execution of that chunk by setting `eval` to `FALSE`. See the difference to the previous chunk:

```{r, eval=FALSE}
print("Success!")
```

**There are typical sources of errors in knitting** when your code runs chunk-by-chunk

- **missing data or packages**: While you may have loaded a library / package earlier on, RMarkdown files are self-contained. So whatever package you may have loaded a few hours ago in RStudio is not available for knitting
    - *Solution*: Check which packages you loaded with `sessionInfo()` and add them
- **missing files**: Files you were able to load in R are not found when loading them in RMarkdown
    - *Solution*: paths inside your RMarkdown file should be specified in relation to the `.rmd` file, not your working directory; paths in your command line should be specified in relation to your working directory


In contrast, **when running individual chunks, you will often encounter errors because you did not execute some prerequisites** - e.g. you have not loaded the data, not loaded a library etc. - for that, include commands that are definite prerequisites for running your file in the setup-chunk (marked with `setup`, usually at the start of the file.)




