Code Cells

May 1, 2026 · View on GitHub

Quarto uses a hashpipe (#|) syntax for code cell options, providing a clean, YAML-based approach that works across R, Python, Julia, and other languages.

Hashpipe Syntax

Code cell options are specified with #| at the start of lines within the code block:

```{language}
#| label: fig-scatter
#| echo: false
#| fig-cap: "A scatter plot of x versus y."
#| fig-width: 8
#| fig-height: 6

# code that produces a scatter plot
```

Important: Options use dashes, not dots. Use fig-cap not fig.cap, fig-width not fig.width.

The hashpipe prefix is #| for R, Python, and Julia; diagram cells use a different prefix. See engines.md for the full table.

Execution Options

Control whether and how code is executed:

OptionDescriptionValues
evalEvaluate the codetrue, false
echoInclude source code in outputtrue, false, fenced
outputInclude results in outputtrue, false, asis
warningInclude warningstrue, false
errorInclude errors (stop on error if false)true, false
includeInclude cell in output at alltrue, false

Examples

Show code but don't run it:

```{language}
#| eval: false

# This code is displayed but not executed
```

Run code but hide it:

```{language}
#| echo: false

# This code runs but is not shown
```

Show fenced code block with attributes:

```{language}
#| echo: fenced

# code here
```

output: asis

output: asis passes the cell output through as raw content without further Quarto processing. Use it when your code prints a pre-formatted markdown or raw string that Quarto should treat as document content.

Requirements:

  • The output must already be valid markdown (pipe table, headings, prose) or a raw block (```{=html}, ```{=latex}).
  • tbl-cap on an output: asis cell does not behave identically to the knitr table-rendering path; prefer a div-wrapped caption for reliability.
```{language}
#| output: asis

# print("| Col A | Col B |\n| ----- | ----- |\n| 1     | 2     |")
```

Figure Options

Options for controlling figure output:

OptionDescriptionExample
fig-capFigure caption"A descriptive caption."
fig-subcapSubcaptions for multiple figures["Plot A", "Plot B"]
fig-widthWidth in inches8
fig-heightHeight in inches6
fig-altAlt text for accessibility"Scatter plot showing..."
fig-alignAlignment"left", "center", "right"
fig-cap-locationCaption position"top", "bottom", "margin"
fig-formatOutput format"png", "svg", "pdf"
fig-dpiResolution in DPI300

Figure Example

```{language}
#| label: fig-analysis
#| fig-cap: "Analysis results showing the relationship between variables."
#| fig-alt: "Scatter plot with trend line showing positive correlation."
#| fig-width: 10
#| fig-height: 6
#| fig-align: center

# code that produces a scatter plot with trend line
```

Multiple Figures

```{language}
#| label: fig-panels
#| fig-cap: "Multiple panel figure."
#| fig-subcap:
#|   - "Distribution of X"
#|   - "Distribution of Y"
#| layout-ncol: 2

# code that produces two figures (one per panel)
```

Table Options

Options for controlling table output:

OptionDescriptionExample
tbl-capTable caption"Summary statistics."
tbl-subcapSubcaptions for multiple tables["Table A", "Table B"]
tbl-colwidthsColumn widths[40, 60] or "auto"
tbl-cap-locationCaption position"top", "bottom", "margin"

Table Example

```{language}
#| label: tbl-summary
#| tbl-cap: "Summary statistics by group."

# code that produces a table
```

Table rendering behaviour differs between the knitr and jupyter engines; see tables.md for details. For markdown table output from code, use output: asis (see the output: asis section above).

Caching and Freeze

Only suggest #| cache: true for R code cells (knitr engine). It is not valid for Python or Julia cells — the jupyter engine silently ignores it.

For Python and Julia, caching is document-level only. Install jupyter-cache (pip install jupyter-cache) and set in YAML front matter:

execute:
  cache: true

For details see https://quarto.org/docs/projects/code-execution.html#cache.

Project-Level Freeze

In _quarto.yml:

execute:
  freeze: auto # Re-render only when source changes

Document-Level Defaults

Set defaults for all code cells in YAML front matter:

title: "My Document"
execute:
  echo: false
  warning: false
  message: false

Or per-format:

format:
  html:
    code-fold: true
  pdf:
    echo: false

Code Display Options

Control how code is displayed in HTML output:

OptionDescriptionValues
code-foldCollapsible codetrue, false, "show"
code-summaryText for fold toggle"Show code"
code-toolsCode tools menutrue, false
code-line-numbersShow line numberstrue, false
code-overflowHandle overflow"scroll", "wrap"

Code Folding

In YAML front matter:

format:
  html:
    code-fold: true
    code-summary: "Click to see code"

Per cell override:

```{language}
#| code-fold: show

# This code is visible by default
```

Code Annotations

Add annotations to explain code:

```{language}
#| code-annotations: hover

step_one()   # <1>
step_two()   # <2>
step_three() # <3>
```
  1. First step description.
  2. Second step description.
  3. Third step description.

Annotation styles: hover, select, below, beside.

Filename Display

Show a filename above the code block:

```{language}
#| filename: "analysis.ext"

# code here
```

R Markdown Migration

R Markdown uses dots (.), Quarto uses dashes (-): fig.capfig-cap, fig.widthfig-width. Options move from chunk header to #| lines. results="asis" becomes output: asis. Setup chunks with knitr::opts_chunk$set(...) become execute: in YAML. See conversion-rmarkdown.md for full details.

Resources