Dyr og Data

Dynamic documents — Introduction

Gavin Simpson

Aarhus University

Mona Larsen

Aarhus University

Wednesday, 19 August 2026

Learning objectives

At the end of this topic you should

  • understand the basics of the literate programming paradigm

  • understand basic Markdown syntax

  • understand how to write YAML

  • understand basic Quarto commands, syntax, & workflow

  • be able to use the RStudio IDE to work with and render Quarto documents

  • be able to write documents using Markdown and Quarto

Literate programming

Quarto is a system for dynamic document creation

Let us change our traditional attitude to the construction of programs: Instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to humans what we want the computer to do

— Donald E. Knuth (1984) Literate Programming

The general idea of dynamic documents comes from literate programming

Mix source code and documentation together, then we can

  • extract the source code from the source file — tangle
  • execute the code to get the compiled results — weave

Literate programming

Two main tasks in the literate programming paradigm

  1. write program code to do computing, and

  2. write narrative text to explain what the code does

In computer code, 2. is largely done through comments and specialised markup

Literate programming

Three main steps in literate programming

  1. parse the source document, separating code from narrative text,

  2. execute the code and return/gather the results

  3. interleave results from executing the code with the narrative text

Dynamic documents

In a dynamic document we mix executable code with narrative text

Executable code can produce text, tables, figures/plots, etc that are combined with the narrative text

The narrative text in a report or paper is typically complex and long

Ideally we’d have a way to write narrative text in a human-readable source file

Quarto

Quarto is a tool for mixing text written in Markdown with executable code (typically R) and for including the outputs of that code in the document

Builds upon previous tools

  • Sweave (Fritz Leisch, 2002) — an early R implementation of these ideas
    • Sweave documents combined R code chunks embedded in a LaTeX document
  • knitr is a newer implementation that allows for greater flexibility than Sweave
  • rmarkdown builds upon knitr and Pandoc to provide a flexible document processing and literate programming tool for R (and other languages)

Quarto

Several technologies are involved

Source: Wickham, Çetinkaya-Rundel, & Grolemund (2023) R for Data Science