Prevent Rmd code chunk from running by using variable when in interactive mode
Asked Answered
P

1

7

When I knit this example .Rmd, the second chunk---as expected---does not evaluate but if I run all chunks interactively, the second chunk executes. What's the cleanest way to accomplish the equivalent of eval=FALSE for interactively running all chunks?

```{r}
RUN <- FALSE
```

```{r eval=RUN}
print("Code ran!")
```
Peaked answered 16/2, 2018 at 22:37 Comment(1)
did you find a solution yet? This would be extremely helpful for developing/writing code, so I could skip chunks that only produce large plotsSolidarity
B
0

A bit old, but here is the closest answer. As of now, chunk options only control code execution during knitting.

However, you can control the execution of that code by wrapping it in an if() statement.

Place the following in your setup chunk or whatever chunk that will initiate the control:

RUN <- FALSE

Then use an if() to control the execution:

if(RUN) {print("Code ran!")}

You can also use the interactive() function to check if you are in interactive mode or not.

I hope this help!

Also, there is this reference: Prevent chunk evaluation in R Notebook interactive

Bellows answered 6/11, 2023 at 9:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.