Collecting commands into a script is the first (and arguably most important) step toward reproducible computing.
Literate Programming is a related technique that combines a script’s computational steps with explanations and computational results.
R implements this pattern through Quarto (nee RMarkdown). Quarto combines
Keeping these pieces in a single document that can be interpreted by both computers and humans helps keep the why/how/what clear, consistent, and accurate.


gt) can enhance how output is
rendered.
content.content dir with the name
gdp_per_capita.qmd# Consider GDP per capita
The **code chunks** below will show how to output
- tables
- plots
```{r}
#| tbl-cap: "A data frame."
library(tidyverse)
gm = read_csv('data/gapminder_data.csv')
gm |>
filter(year == 1952) |>
arrange(desc(gdpPercap)) |>
head(3)
```
Consider the dplyr code above; what is it doing? Could you explain what that code is doing to a colleague who wasn’t in this workshop? Try improving the table caption above and re-run that code chunk.
Create another code chunk that uses the gt package to improve the table aesthetics.
```{r}
library(gt)
gm |>
filter(year == 1952) |>
arrange(desc(gdpPercap)) |>
head(3) |>
gt()
```
```{r}
#| fig-cap: "A plot"
gm |> ggplot(aes(x = year, y = gdpPercap, color = continent, group = country)) +
geom_line() +
facet_grid(cols = vars(continent)) +
labs(
title = 'GDP per Capita 1952 - 2007',
x = 'Year', y = 'GDP per Capita') +
theme_bw() +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1))
```
Consider the ggplot code above; what is it doing? Try improving the figure caption above a re-running that code chunk.
Render into a new html file. Note the new html file in the file pane along with a new folder of html supporting docs.
Quarto metadata (at the top) controls how the whole document is rendered
---
title: "Untitled"
format: html
editor: visual
---
Adjust the title from “Untitled” to “Consider GDP per capita” and re-render the document.
embed-resources: true as shown below.
(Indenting matters)---
title: "Consider GDP per capita"
format:
html:
embed-resources: true
editor: visual
---
Re-render the document and note the html file is slightly larger. A self-contained html file is easy to shared (e.g. email) with a colleague.
Visual tab or by directly
typing markdown in the Source view.