2

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.")
```
Rainer
  • 8,347
  • 1
  • 23
  • 28

1 Answers1

4

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


shafee
  • 15,566
  • 3
  • 19
  • 47