Home > other >  Display Block of R Code in Knitr With Evaluation Turned Off
Display Block of R Code in Knitr With Evaluation Turned Off

Time:04-23

I am writing a document with fairly resource intensive R code. I want to prevent execution of one block of R code in knitr which is giving me document timeout error in Overleaf.

In R studio, this can be done using eval = FALSE. I want to recreate this in knitr. So far, the only way I have found is to suppress errors using <<setup, include=FALSE, cache=FALSE>>= muffleError <- function(x,options) {} but it only works on the entire document.

I specifically want to prevent evaluation but show the R code.

CodePudding user response:

Is this what you want to do, or have I misunderstood? The eval = FALSE is in one code chunk and the second chunk still plots.

---
title: "A Test Knit"
output: html_document
---

## Show code but don't run

```{r, eval = FALSE}
summary(cars)
```

## Run and render plot

```{r}
plot(pressure)
```
  • Related