Your task in this exercise is to create an R Markdown
document that reports an analysis based on the (synthetic) data from the
GESIS Panel Special Survey on the Coronavirus SARS-CoV-2 Outbreak in
Germany. The output should be an HTML document. To
come up with your own ideas for toy examples that you could include in
your report, make sure to consult the codebook for the original
data.
Note: We have created an exemplary
R Markdown report that you can use as inspiration or a
starting point for creating your document. You can find the
.Rmd file as well as the HTML output in the
solutions folder within the workshop materials:
Example_RMarkdown.Rmd and
Example_RMarkdown.html.
R Markdown document, give it a meaningful
name, and save it somewhere in your project folder where you will find
it. The output format that we want to use for this exercise is
HTML.
R Markdown document is
through the RStudio GUI.
R Markdown document in
RStudio via File -> New File -> R
Markdown in the menu.
YAML header of the document, so that it
includes the following: a meaningful title, an author name, the current
date.
YAML header
through the RStudio GUI when creating a new document. To add
the current date, you can use inline R code in the
respective field within the YAML header. Remember that you
need to enclose the YAML header in — .
r Sys.Date()”
output: html_document
Include a setup chunk in your document. Use this chunk to set the
knitr options so that the code is displayed in the output
document but messages are suppressed.
Three other things we want to do in the setup chunk:
For the general options (i.e., the one not related to
knitr), you can check ?options.
You probably do not want to include the chunk options as code output
in the resulting HTML document. You can achieve this by
setting the chunk option include to FALSE for
the setup chunk.
Chunk options: {r setup, include=FALSE} (for the code to be included in this chunk, see the following solution box)
NB: In yourR Markdown document, a code block
needs to start and end with three backticks. Remember that in
RStudio you can use the keyboard shortcut Ctrl + Alt +
I (Windows & Linux)/Cmd + Option +
I (Mac) for inserting code chunks.
knitr::opts_chunk$set(echo = TRUE,
message = FALSE)
options(scipen = 10,
digits = 2)
Now you can start to create some content for your document. You can get as creative as you want, but we suggest that the document (at least) includes the following:
two different levels of headings
some basic text formatting and links
some inline code
multiple code chunks (with different chunk options)
at least one table
at least one figure
To check if everything works the way you expect, you should knit the
document periodically. Also remember that we have created (and also
knitted) an exemplary report which you can find in the
solutions folder.
tidyverse collection of
packages for wrangling the data. If you are not familiar with that
(e.g., the use of pipes %>%) or prefer other packages
for creating tables or plots, feel free to change anything you like in
that document.
Example_RMarkdown.Rmd and the
resulting Example_RMarkdown.html for some examples and
inspiration. Also make sure to consult the codebook for the original data
set. Remember that only a subset of these variables (i.e., the
numeric ones) are included in the synthetic data file that we use in
this course (and that all values < 0 have been recoded as
NA).
R session (OS, R version, loaded
packages) to the document. Add a section named Reproducibility
information at the end of your document and display this
information there.
base R function to access information about
your session (function name hint 1) and another one for printing it
(function name hint 2). You can exclude information about your
locale settings there.
sessionInfo() %>%
print(locale = FALSE)