You can find the solutions for this exercise as well as the following
ones in the exercises
folder in the workshop material. You
can also navigate the workshop material online (including
exercises and solutions).
You can copy code from the exercise and solution files by clicking on the small blue clipboard icon in the upper right corner of the boxes showing the code.
Some of the exercise require you to add text and R code. Feel free to
copy from the example paper in the folder
exercises/example_manuscript
. We do, however, encourage you
to use material from a project of your own, if possible. It will be a
lot more fun.
In this exercise, you will create a first R Markdown document. The example data we use here is taken from the example manuscript provided with the workshop material. However, we encourage you to use your own data for this and the following exercises.
Customize the YAML front matter of your R Markdown document. Add
abstract
field to the YAML front matterrmarkdown::html_document()
.
Add some text to the document. You can copy the example paper introduction or text for a project of your own. Try out some of the text formatting, e.g.,
You can find a quick reference guide to markdown formatting syntax in RStudio. Go to Help > Markdown Quick Reference.
To switch to the visual editor click the button at the top of your Rstudio editor pane.
Don’t forget to add the bibliography file to the YAML front matter for your citations to render properly.Add some analyses code to the document. You can copy the analysis code for the example paper or use code for a project of your own.
Insert a new code chunk either by clicking , or with Ctrl + Alt + I.
Be careful not to break code chunks. The enclosing elements
```{r}
and ```
have to be on lines of there
own and cannot be preceeded by white space.
knitr
documentation for a complete list of chunk options.
Add a setup chunk at the top of your document. In this chunk
knitr
package andYou can insert a new code chunk by clicking or with the keyboard shortcut Ctrl + Alt + I.
See the documentation forknitr::opts_chunk
.
To document the versions of all packages that you used for the
analysis, let’s document your R
session (operating system,
R version, R packages, etc.).
sessioninfo::session_info()
.
Create a brief presentation of your findings. Use R Markdown to either create
There are many great examples which you can adapt online.
xaringan builds on a powerful JavaScript library called remark.js. This library has many powerful advanced features. If this is something you are interested in, I recommend the following resources:
After you have tried yourself, feel free to have a look at our solutions.