Automation with Quarto
Quarto is an open-source publishing system that extends Markdown with the ability to execute code inside the document at render time.
.qmd) is a Markdown file with embedded Python, R, or Bash chunksThe Quarto extension provides a preview button and render command directly in the editor.
Built-in Quarto support, including a visual editor and Render button.
Document formatting can be applied globally or to specific document types (HTML, PDF, etc.,):
Code chunk parameters can be defined globally in the front matter - these will be used as defaults unless overridden in an individual code block:
Use params to parameterize inputs — useful when the same report is run against different datasets:
Reference in code chunks via params$tree_file (R) or params['tree_file'] (Python).
Override from the command line with --execute-params.
The key difference between a code block and a code chunk are the brackets ({}) around the language:
Execution settings can be set in {} or using the #| format shown above.
| Option | Behavior |
|---|---|
eval |
Run code |
echo |
Show code |
output |
Show code result |
include |
Run code but hide all output |
warning |
Show code warnings |
message |
Show code messages |
error |
Show code errors |
cache |
Cache execution result |
With reticulate, R and Python chunks can share objects.
step 1
step 2
Consolidate all imports into a single “dependency chunk” at the top of the document:
Once imported, dependencies are available to all subsequent code chunks!
Bash Scope
Bash chunks are executed as independent subprocesses — variables defined in one Bash chunk are not available to subsequent Bash chunks.
R
Python
Example output:
| sample_id | organism | coverage | qc_pass |
|---|---|---|---|
| SRR001 | Influenza A | 142.3 | TRUE |
| SRR002 | Influenza B | 98.7 | TRUE |
| SRR003 | SARS-CoV-2 | 34.1 | FALSE |
| SRR004 | SARS-CoV-2 | 201.5 | TRUE |
R
Python
Example output:
Tip
Alternatively, export a figure (e.g., ggsave()) and embed it with standard Markdown: 
Integrate computed values directly into narrative text:
| Language | Syntax |
|---|---|
| Python | `{python} len(df)` |
| R | `r nrow(df)` |
Python requires curly brackets for inline references; R does not.
Example:
This report includes
`{python} len(df)`samples.
Rendered:
This report includes 100 samples.
An example report can be found here.
Structure
├── _quarto.yml
├── data
│ ├── mira
│ │ ├── mira_output-1.csv
│ │ └── mira_output-2.csv
│ ├── h1.nwk
│ └── samplesheet.csv
├── genome_report.html
├── genome_report.qmd
└── src
└── report
├── __init__.py
├── config.py
├── data.py
├── display.py
├── io_ops.py
├── map.py
├── timeline.py
└── tree.py
Key Files
| File / Directory | Description |
|---|---|
genome_report.html |
Rendered HTML output — the final report that would be shared. |
genome_report.qmd |
Quarto source file. Relies on data/, src/, and _quarto.yml. |
data/ |
Sample data used each run: samplesheet, MIRA output, tree file. |
src/ |
Custom Python module imported and executed within code chunks. |
_quarto.yml |
Params config updated each run, passed via --execute-params. |