简体   繁体   中英

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

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.")
```

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.")
```

使用 r 代码作为块选项


The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM