Figure cross referencing and knitr::read_chunk #8758
-
DescriptionHi, ---
title: "Test figure labels from code chunks"
format:
pdf:
keep-md: true
keep-tex: true
---
## Quarto
```{r}
#| echo: FALSE
knitr::read_chunk("qq_code.R")
```
```{r }
#| label: Setup
#| echo: FALSE
#| warning: false
#| message: false
```
```{r}
#| label: APlot
#| echo: FALSE
#| fig.cap: "A caption"
#| fig.link: fig-APlot
```
Figure @APlot
and ## ---- Setup ----
library(tidyverse)
data(mtcars)
## ---- APlot ----
ggplot(mtcars, aes(x=disp, y=mpg, colour=factor(cyl))) + geom_point()
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Label needs a prefix such as Side note: In the end your Quarto document should look like the following: ---
title: "Test figure labels from code chunks"
format:
pdf:
keep-md: true
keep-tex: true
execute:
echo: false
---
## Quarto
```{r}
#| include: false
knitr::read_chunk("qq_code.R")
```
```{r}
#| label: Setup
#| include: false
#| warning: false
#| message: false
```
```{r}
#| label: fig-APlot
#| ref-label: APlot
#| fig-cap: "A caption"
#| fig-link: fig-APlot
```
Figure @fig-APlot |
Beta Was this translation helpful? Give feedback.
Label needs a prefix such as
fig-
to be accounted as a cross-reference, see https://quarto.org/docs/authoring/cross-references.html.Side note:
FALSE
is R syntax. In yaml, it isfalse
. In Quarto, options use-
not.
as word separator.Use
execute
to set globally option such asecho: false
, see https://quarto.org/docs/reference/formats/html.html#execution and https://quarto.org/docs/computations/execution-options.html.Finally, headers, list, and code cells should be surrounded by empty lines to avoid parsing issues.
In the end your Quarto document should look like the following: