包括不在 Rpresentation Markdown 运行的代码

我有一个。RStudio 中的 Rpres 文件。我希望包含代码,但不要运行它(我只是展示代码来解释它是如何工作的)。是否有可能实现这一点(并确保它不会产生错误,因为它没有运行) ?

74934 次浏览

Have you tried eval=FALSE in the knitr code chunk options? e.g.:

```{r eval=FALSE}
print("Don't run me")
```

{r, eval=F, echo=T} will include the R source code in the output file while it is not evaluated

Posting for anyone who may come across this like I have. I've found that for small examples (if you don't want to use chunks), you can also just use back ticks like you would with regular markdown inline, but just don't add the "r" at the beginning:

`plot(cars)`

Will print the code itself, but will not print the plot.