Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Evaluate code block in quarto dependant on evaluation of an R variable

Tags:

r

quarto

I have the following quarto document, and I want to execute the second code block depending on the value of OK. As below, it does not work. I tried double and triple backticks, using only OK, but nothing worked. How can I do this?

---
title: "Test"
format: html
---

## Set a variable

```{r}
OK <- FALSE
```

## Running Code depending on value of `OK`

```{r}
#| eval: `r OK`
print("OK is TRUE - otherwise you won't see anything here.")
```
like image 969
Rainer Avatar asked Oct 15 '25 04:10

Rainer


1 Answers

You can use R code as chunk option values by prefacing them with !expr.

---
title: "Test"
format: html
---

## Set a variable

```{r}
OK <- FALSE
```

## Running Code depending on value of `OK`

```{r}
#| eval: !expr OK

print("OK is TRUE - otherwise you won't see anything here.")
```

use of r code as chunk option


like image 177
Shafee Avatar answered Oct 17 '25 18:10

Shafee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!