2

I quite often make mistakes in the text part of *.Rmd documents and, in some cases, fixing and running knit() implies re-running R commands that can take a while. Therefore, it is an advantage running the .Rmd document without actually executing the R code first, then fix any typos and structure errors and then run again with evaluation. I know this can be achieved by including

knitr::opts_chunk$set(eval = FALSE)

in the .Rmd

but I would prefer avoiding to actually edit the .Rmd file and using an equivalent way at the command line, something like

knit("file.Rmd", eval=FALSE)

Is actually there a way to achieve this at the command line?

user2955884
  • 405
  • 2
  • 11

2 Answers2

4

You do not need to edit the .Rmd file. You can just run

knitr::opts_chunk$set(eval = FALSE)

before running knitr::knit(); knitr will respect the global chunk options you set before calling knitr::knit().

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
0

I think you might consider to add cache=TRUE to the options in knitr, that will avoid running again the code chunk again if you didn't change anything within it.

https://bookdown.org/yihui/rmarkdown-cookbook/cache.html

You can get a general effect if you add this at the beginning of the .Rmd file, like for example:

knitr::opts_chunk$set(echo = TRUE, cache = TRUE)