Writing with code

An introduction to Literate Programming with R and Quarto

Dr. Jerid Francom

Jan 19, 2024

Overview

  • Literate Programming
  • Quarto
  • Lab 00: Writing with code

Literate Programming

Literate Programming

Literate programming is an approach to programming in which code, documentation, and results are all interwoven into a single document.

  • Encourages stating the problem and solution in plain language
  • Encourages writing code that is easy to read and understand
  • Includes more explicit documentation than traditional code comments
  • Facilitates reproducible research

Quarto

Quarto

Quarto is a document generation system that supports literate programming. It is designed to support a wide range of document types (HTML, PDF, Word, etc.) and programming languages (R, Python, Julia, etc.).

---
title: "My First Quarto Document"
format: html
---

## Intro to Quarto

This is a code block which simply prints a message.

```{r}
#| label: example-code

print("My name is Quarto")
```

Quarto + Markdown

In Quarto, prose is written in Markdown. Markdown is a lightweight markup language that is easy to read and write.

Markdown HTML
# Heading Heading
**bold** bold
footnote^[Footnote info...] footnote1
- bullets - bullets
[links](https://quarto.org) links

Quarto + R

Code blocks in Quarto introduce sections where code can be executed.

```{r}
#| label: fig-example-plot
#| fig-cap: A simple plot

ggplot(
  data,
  aes(x = cat, y = passive)
) +
  geom_col() +
  labs(
    x = "Categories",
    y = "Passives (count)"
  )
```
Figure 1: A simple plot

The code here generates the plot in Figure 1.

Lab 00: Writing with code

Setup

In lab 00, you will create a basic Quarto document and explore some of the features of Quarto.

  • Copy the clone URL for the lab 00 repository
  • Open RStudio (with Docker Desktop running)
  • Create a new project from version control
  • Paste the clone URL into the repository URL field
  • Follow the instructions in the README.md file

Footnotes

  1. Footnote info…