Quarto Reports
Every Monday, Priya, a data analyst at the Inkwell Books chain, ships the same thing: last week's sales report. For a long time she did it by hand. She ran her R code, copied the numbers into a Word document, pasted a chart, and wrote a summary sentence. Then one Monday the data changed at the last minute. She updated the chart but forgot the sentence, and the report went out with a headline that said one revenue and a chart that showed another.
That mistake has a name: copy-paste drift, and it is exactly what this lesson removes. With Quarto (and its older sibling R Markdown), the prose, the code, and the figures all live in one file. You render that file once and every number in the text is computed by R, never typed. Then you make it a template that re-runs for any store or any week, with no editing at all.
The widget below is Priya's report. Toggle between Source (.qmd), the plain text she writes, and Rendered, the finished page R produces from it.
By the end of this lesson you will be able to:
- Name the three parts of a Quarto document (the YAML header, the prose, and the code chunks) and say what "render" does
- Write a code chunk and an inline expression so a figure, a table, or a number is produced by R, not pasted
- Explain why this makes a report reproducible: change the data once and every number re-flows
- Describe what render turns your file into, and get HTML, PDF or Word from the same source
- Parameterize a report with
params:so one template re-runs for any input
Prerequisites: you can run R and load a package with library(), you have built a basic ggplot (data, then aes(), then a geom) in The Grammar of Graphics, and you know the dplyr verbs filter() and summarise() from The dplyr Verbs. Every new term is defined as it appears.
One file, three parts
A Quarto document is a single plain text file with the extension **.qmd (Quarto markdown). It is not an app and not a server. You write it, then you render** it: render means "run the file and produce a finished document," a web page, a PDF, or a Word file. R Markdown (.Rmd) works the same way and Quarto is its modern successor, so everything here applies to both.
Every .qmd is made of just three kinds of content. Toggle the widget above between Source and Rendered and you can see all three:
- The YAML header: a small settings block at the very top, fenced by
---lines. It holds the title, the author, and the outputformat:. (YAML is just a simplekey: valuetext format for settings.) - The prose: ordinary markdown text, headings, sentences, lists, the words a reader actually reads.
- The code chunks: blocks of R fenced by ```
`{r}```. When you render, R runs each chunk and drops its result, a table or a chart, straight into the document.
Everything in this lesson is built from Priya's six Inkwell Books stores. Each lesson runs in a fresh R session, so we create that data right here (run this once, and every later block can use it):