Reproducible reports with Quarto
A report becomes difficult to maintain when its numbers live in a spreadsheet, its figure comes from a script, and its text contains a copied result. Quarto puts the analysis and the explanation in one document. A render executes the code and inserts its results into the text, tables, and figures.
This lesson builds an R report for two invented assay markers, IL6 and CXCL10. One parameter selects the marker. The source file stays the same while the selected observations and every displayed result change together.
The measurements use arbitrary units and do not come from a biological study. Their purpose is to demonstrate a report that preserves donor pairs. The example computes descriptive differences without a hypothesis test.
Get the complete example
Section titled “Get the complete example”Download the report source package.
It contains report.qmd, the input CSV, a render script, and environment
information. The source package works independently of the companion repository.
You can also open the rendered IL6 report and CXCL10 report. Each HTML file contains its figure and display resources, so it remains readable after a download.
Extract the package and open a terminal in its folder. With Podman installed, these commands use a public Bioconductor image that contains Quarto 1.9.38, R 4.6.1, knitr 1.51, and rmarkdown 2.31. The first run downloads the image if needed; the report itself executes without network access.
bash render.sh IL6 report_il6.htmlbash render.sh CXCL10 report_cxcl10.htmlIf those tools already exist in your analysis container, the equivalent Quarto commands are below. Give each result a separate filename so the second render does not replace the first.
quarto render report.qmd --to html --output report_il6.html -P marker:IL6quarto render report.qmd --to html --output report_cxcl10.html -P marker:CXCL10Declare the report and its parameter
Section titled “Declare the report and its parameter”A .qmd file combines Markdown text with executable code blocks. Its YAML
header selects the output format and declares marker, the value that the
command line overrides. This example uses R, so knitr executes the code and
exposes the parameter as params$marker.
---title: "Paired assay report"subtitle: "This example uses invented measurements."format: html: embed-resources: true toc: true theme: default lang: enexecute: echo: false cache: false freeze: false error: falseparams: marker: "IL6"---echo: false hides source code in the report while retaining its results.
The source remains in the .qmd download. embed-resources: true includes the
figure and display resources in the HTML file.
Quarto uses {r} as the label of an executable R block. The complete source
already contains the blocks below in their required order.
Check the input before computing a result
Section titled “Check the input before computing a result”The input has one row for each donor, condition, and marker combination. The same donor appears once under control and once under treatment for each marker. An accidental duplicate would give that donor more weight, so the report rejects duplicate keys before it computes a mean.
data <- read.csv("inputs/assay_values.csv", stringsAsFactors = FALSE)required <- c("donor", "condition", "marker", "value")stopifnot(identical(names(data), required), !anyNA(data))stopifnot(is.numeric(data$value), all(is.finite(data$value)))stopifnot(all(data$condition %in% c("control", "treated")))stopifnot(!anyDuplicated(data[c("donor", "condition", "marker")]))dir.create("outputs", showWarnings = FALSE)cat(sprintf("Input rows: %d\n", nrow(data)))cat(sprintf("Donors: %d\n", length(unique(data$donor))))cat(sprintf("Markers: %s\n", paste(unique(data$marker), collapse = ", ")))Input rows: 48Donors: 12Markers: IL6, CXCL10These checks test the input structure. They do not establish that a measured signal has the correct units or that an assay measures the intended target. Keep those facts with the source data when you adapt the example.
Keep each donor’s pair together
Section titled “Keep each donor’s pair together”The fallback value lets the same block run as an ordinary R script. During a
Quarto render, params already exists and contains the selected parameter.
if (!exists("params")) { params <- list(marker = "IL6")}stopifnot(is.character(params$marker), length(params$marker) == 1L)stopifnot(params$marker %in% unique(data$marker))selected <- data[data$marker == params$marker, ]paired <- reshape(selected[c("donor", "condition", "value")], idvar = "donor", timevar = "condition", direction = "wide")stopifnot(all(c("value.control", "value.treated") %in% names(paired)))stopifnot(!anyNA(paired), nrow(paired) > 1L)paired <- paired[order(paired$donor), ]paired$change <- paired$value.treated - paired$value.controln_pairs <- nrow(paired)mean_change <- mean(paired$change)change_label <- formatC(mean_change, format = "f", digits = 2)summary_table <- data.frame( Quantity = c("Control mean", "Treated mean", "Mean paired change"), Value = c(mean(paired$value.control), mean(paired$value.treated), mean_change))marker_file <- tolower(params$marker)write.csv(summary_table, file.path("outputs", paste0(marker_file, "_summary.csv")), row.names = FALSE)cat(sprintf("Selected marker: %s\n", params$marker))cat(sprintf("Complete donor pairs: %d\n", n_pairs))cat(sprintf("Mean treated minus control: %s arbitrary units\n", change_label))Selected marker: IL6Complete donor pairs: 12Mean treated minus control: 7.00 arbitrary unitsThe difference is treated minus control for each donor. Sorting the donor
identifiers makes the displayed order stable, while reshape() matches the
observations by their identifiers. Their position in the CSV does not define
the pair.
Insert the calculated value into a sentence
Section titled “Insert the calculated value into a sentence”The report uses inline R expressions instead of a number typed into the text. Place this sentence after the block that creates its variables.
The selected marker is `{r} params$marker`.The report contains `{r} n_pairs` paired donors.The mean paired change is `{r} change_label` arbitrary units.The text receives the same values as the exported summary. Editing the marker name in a heading would change only a label; changing the parameter reruns the selection and calculation.
Add a table and a paired figure
Section titled “Add a table and a paired figure”knitr::kable() converts the computed table to Markdown. The chunk option
results: asis lets Quarto render that Markdown as a table.
#| results: asisprint(knitr::kable(summary_table, format = "pipe", digits = 2, col.names = c("Quantity", "Arbitrary units")))The figure connects the two measurements from each donor. Its filename also uses the selected marker, so each render keeps its own image.
#| fig-alt: >#| Each line connects control and treated measurements for one invented donor.#| The title identifies the selected marker.figure_path <- file.path("outputs", paste0(marker_file, "_paired.png"))png(figure_path, width = 1200, height = 760, res = 145)par(mar = c(4.2, 4.8, 3, 1), las = 1, bty = "l")limits <- range(c(paired$value.control, paired$value.treated))plot(c(1, 2), limits, type = "n", xaxt = "n", xlab = "", ylab = "Invented assay value, arbitrary units", xlim = c(0.75, 2.25), main = paste(params$marker, "within each donor"))axis(1, at = c(1, 2), labels = c("Control", "Treated"))offsets <- seq(-0.08, 0.08, length.out = n_pairs)for (index in seq_len(n_pairs)) { lines(c(1, 2) + offsets[index], c(paired$value.control[index], paired$value.treated[index]), col = "#b5bec8", lwd = 1.5)}points(1 + offsets, paired$value.control, pch = 19, col = "#32658b", cex = 1.3)points(2 + offsets, paired$value.treated, pch = 19, col = "#b76525", cex = 1.3)invisible(dev.off())knitr::include_graphics(figure_path)
The offsets separate overlapping points; their horizontal positions carry no measurement. Both marker reports retain the same donor pairs, but their arbitrary scales do not support a comparison of biological potency.
Rerun the document when its inputs change
Section titled “Rerun the document when its inputs change”The example disables caching and freezing. Each render reads the input CSV and executes the analysis again. A cached result can outlive an edited external file, so a report with cached execution needs an explicit rule for input changes.
An HTML file preserves the displayed result, but it cannot replace the source document, input data, parameters, or environment. Keep these together when you send an analysis to another researcher. The source package includes all files needed to render this example in its public container.
Scientific references
Section titled “Scientific references”Allaire and colleagues, 2025 describe Quarto, the publishing system that executes and renders the report.
Xie, 2025 documents knitr, the R engine that evaluates the report code and inline expressions.
Xie, Allaire, and Grolemund, 2018 describe R Markdown and the R document tools used by Quarto’s knitr engine.
Further reading
Section titled “Further reading”The Quarto parameter guide explains how the YAML values reach params and how the command line overrides them. Use it when one source must produce reports for several datasets or analysis settings.
The inline code guide explains how computed values enter a sentence. It also distinguishes executable expressions from literal examples of their syntax.
The HTML resource guide explains which display files Quarto embeds in an HTML document. This option makes the rendered report portable without making its underlying analysis editable.
The execution guide explains code visibility, errors, caching, and related options. Read it before changing when your report reuses an earlier computation.