Disable execution of chunk with R markdown eval variable

Viewed 1232

I am trying to define a set of variables to control on/off of the execution of chunks in my Rmarkdown. However, I noticed that with the variable1 = FALSE and {r chunk1, eval = variable1}, the chunk will be still executed (by hitting "Run All Chunks" button). For knitting, this approach works, and the chunk will not be evaluated. Is there anything that I have missed.

For example, the following Rmarkdown will execute pressure1 and plot the pressure with eval = varaible1, but eval =FALSE worked for pressure2 and disable the chunk.

enter image description here

---
title: "Untitled"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r switches, include=FALSE}
variable1 = FALSE
```

```{r cars}
summary(cars)
```

```{r pressure1, eval=variable1}
print("pressure1")
plot(pressure)
```

```{r pressure2, eval=FALSE}
print("pressure2")
plot(pressure)
```
0 Answers
Related