Any idea of using R inline code control chunk option "include"? #6648
Replies: 3 comments
-
Could you share a small self-contained "working" (reproducible) example to work with, i.e., a complete Quarto document or a Git repository? Thanks. This being said, see https://quarto.org/docs/computations/r.html#chunk-options (at the end of the linked section). 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.
-
Not currently. The fundamental reason is that quarto needs to support both knitr and jupyter engines, and this is not a feature that's currently supported in jupyter. |
Beta Was this translation helpful? Give feedback.
-
You can't use inline knitr R code inside a YAML option value field. That is not a syntax that will work. Reason is simple: We need to parse the YAML before any of inline evaluation happens. Have a look at how chunk options are written for R chunks evaluated with knit engines. https://quarto.org/docs/computations/r.html#chunk-options FWIW there is a specific feature for ---
title: "Reproducible Quarto Document"
format: html
---
```{r}
apple_is_square <- TRUE
```
Then, I don't want the following chunk included in my output file since `apple_is_square <- TRUE.`
```{r}
#| label: I love my round apple
#| include: !expr isFALSE(apple_is_square)
tbl <- data.frame(v1 = c("a","b","c"), v2 = c(1,2,3))
tbl
``` Reminder: this works only with knitr engine as this is a knitr feature directly (not working with |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
I would like to control if the specific chunk is included in my output file by using
ifelse()
function of R.Here is an example:
I defined something previously:
Then, I don't want the following chunk included in my output file since
apple_is_square <- TRUE
. I did:Apparently, it does not work in this way, quarto said:
Question: Is there any way that I can choose to include the chunk according to the value of
apple_is_square
?Beta Was this translation helpful? Give feedback.
All reactions