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.

Exercise 1

Create a new 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.
The easiest way to create a new R Markdown document is through the RStudio GUI.

Exercise 2

Create/edit the YAML header of the document, so that it includes the following: a meaningful title, an author name, the current date.
You can already specify some parts of the 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 — .

Exercise 3

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:

  • set the “penalty to be applied when deciding to print numeric values in fixed or exponential notation” to 10
  • set the number of significant digits to print to 2

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.

Of course, if you want to use additional/other packages, you can also add those to the setup chunk.

Exercise 4

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

We also suggest that you loosely follow the structure of a classic research paper (Research Question, Methods, Results), but each of the sections should be very brief.

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.

Please note that we use several different packages in that example document. For example, we make use of the 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.

Exercise 5

To further increase reproducibility, let’s add some information about your 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.
You can use a 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.