Reproducible dynamic report generation with and Quarto

Author

NC

Onyxia

Check out the slides below or click here to view the slides in full screen.

One of the major challenges in research and data analysis is the transparent and reproducible communication of results, as well as collaboration. Reproducible publications offer a solution to this challenge by integrating code, data, and analyses into a format that allows anyone to understand the data processing steps that were implemented and to reproduce the exact results, provided they have the same environment.

Quarto, the tool that succeeded to R Markdown, makes it possible to produce text documents while natively integrating chunks of R code. This helps streamline the writing process of a publication by greatly reducing the number of manual steps required to include graphics or code in a document: rather than having Stata code that generates Excel/Calc outputs which are then integrated into a Word document or transformed into LaTeX tables, we rely on a single source document that contains both the text and the code that produces the outputs of the final document.

With Quarto, we are able to separate content from presentation. This allows us to focus on the most important aspects: the substance of the analysis.

An example of such a formatted report is available on this page.

Note

This practical session is less guided than usual in order to give you more freedom to explore and produce a document.

1 Initializing the document

Exercice 1: Creating the file
  1. Click on File > New file > Quarto document:
    • Provide a title and an author for the report
    • Choose HTML as the output format
    • Uncheck the Use visual markdown editor option
  2. Save the file under the name report.qmd.
  3. In the file header, modify the publication metadata (title, author, date, etc.) using some of the options from this page.
  4. Write a first sentence in the body of the document using one or two elements of Markdown syntax for formatting. For example, make part of the text bold.
  5. Add a level-2 heading (two #) to create an About section and write one or two sentences in it.
  6. Render the document by clicking on the Render button:
Exercice 2: Inserting R outputs
  1. Choose one of the chapters we previously worked on for which we produced a graph or a map. Reuse the example code from the solution (data import and visualizations) and insert it into the document.

  2. Compile the document. If there are errors, read them carefully and fix them in order to obtain a reproducible document.

  3. Use the GT package to create a nice table, for example a descriptive statistics table (a mean, for instance).

Exercice 3: Styling

Customize the output to obtain an aesthetically pleasing document. To do so, you may use a template.

Note

On a Mac , some useful characters are more difficult to type. For example, | can be obtained using the following shortcut: Shift + Option + L