Week 8: Literate programming

2025-06-19

Welcome to Week 8

Theme: Literate programming

This week, you’ll:

  • be introduced to the Quarto publishing system
  • learn some Markdown
  • and build a report with text and visualisations

What is literate programming?

‘Literate programming’ is a blending of executable code and prose. It promotes better communication and understanding by making code more human readable.

Programming is best regarded as the process of creating works of literature, which are meant to be read.

Knuth 1992

In practice

RMarkdown

Jupyter Notebook

Quarto

Quarto is an open-source publishing system developed by Posit, the creators of RStudio. It uses .qmd documents to combine code and text in static and interactive outputs like HTML, Word documents, slides and dashboards.

Image: Allison Horst

How Quarto works

Image: Posit

Setup and installation

There are two ways to install Quarto:

  1. Download the Quarto command line interface (CLI) from the website.

  2. Or open the Terminal and run:

python3 -m venv quarto # create a virtual environment
quarto\Scripts\activate.bat # activate the environment
pip install quarto-cli # download and install


Then install the Quarto extension in VS Code.

The structure of a .qmd file

  • A YAML header with instructions for the output
  • Prose with optional Markdown formatting
  • Chunks of Python code surrounded by ```{python}
---
title: "Gapminder"
format:
   html: 
    self-contained: true
execute:
  echo: false
jupyter: python3
---

Data on life expectancy at birth, GDP per capita and total population are provided for 142 countries between 1952 and 2007 courtesy of [gapminder](https://www.gapminder.org/data/).

```{python}
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
gapminder = pd.read_csv("data/gapminder.csv").query('year==2007')
fig, ax = plt.subplots(figsize = (7, 5))
sns.scatterplot(data=gapminder, x='gdpPercap', y='lifeExp', hue='continent')
ax.set_xlabel('GDP per capita', size=12 )
ax.set_ylabel('Life expectancy', size=12)
ax.set_title('Relationship between life expectancy and income, 2007', size=14)

Let’s Dive Into The Live Session