How can I use a Quarto variable to include a code block? #6768
-
DescriptionI am trying to de-clutter a Quarto markdown document, using variables to include code blocks. I've created a
with the following code in the
But the code is not executed. Is it possible to do this? Do I need to escape any character? Would it be easier to use Quarto includes instead of variables? Nevertheless it would be more convenient to use variables, since it will allow to store multiple code chunks in a single Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
I believe you want to store your code cell in a Quarto document and use the include shortcode which is the tool to include and evaluate, see https://quarto.org/docs/authoring/includes.html. For more, please provide a complete and small reproducible example to work with, i.e., a complete Quarto document or a Git repository. You can share a Quarto document using the following syntax, i.e., using more backticks than you have in your document (usually four ````qmd
---
title: "Reproducible Quarto Document"
format: html
---
This is a reproducible Quarto document using `format: html`.
It is written in Markdown and contains embedded R code.
When you run the code, it will produce a plot.
```{r}
plot(cars)
```
The end.
```` |
Beta Was this translation helpful? Give feedback.
-
Thank you for your response the view:
arvores: |
{python}
#| echo: false
#| label: tbl-test
#| tbl-cap: Volumes
Markdown(tabulate(data,headers=data.columns,showindex=False)) and the # Volume
{{< var view.arvores >}}
|
Beta Was this translation helpful? Give feedback.
-
I do believe it would be easier to use Also I am not sure shortcode handler like Also related to |
Beta Was this translation helpful? Give feedback.
-
The technical reason that what you're trying to do doesn't work is that the resolution of (Yes, we should have better documentation on this. We're working on it!) |
Beta Was this translation helpful? Give feedback.
I believe you mean using
include
? It would be a lot easier if you share a complete reproducible example when you reply something is not working. It was reminded to you earlier at #6768 (comment)Here what I tested
Results:
quarto render index.qmd
echo: false
works, and table is correc…