knitr chunk option eval=TRUE, echo=TRUE, include=FALSE

喜欢而已 提交于 2020-05-14 07:09:47

问题


I use RMarkdown and knitr for dynamic report generation.

When knitting a document, I would like to have the code from an Rmarkdown chunk included in the knitted document and run the code -- but not show the output. That is, I would like to be able to do what this code suggests:

eval=TRUE, echo=TRUE, include=FALSE

... and make knitr run the code (eval = TRUE), show the code (echo = TRUE), but not show the lengthy output (attempted with include = FALSE), but my attempts fail.

Does such an option exist with knitr? Or is it possible to program this with a hook in knitr?

(using only include=FALSE runs the code, but does not show the code.)

(Notification of cross-posting: I posted this question at RStudio support a week ago, but have not received any answer indicating yes or no, or how to achieve what I want).


回答1:


If I am understanding your problem correctly, the issue is the include=F option. You should try instead to use results = "hide". Here is how you can set it at the beginning of your Rmarkdown document so that it is the default setting.

```{r}
knitr::opts_chunk$set(eval = TRUE, echo = TRUE, results = "hide")
```


来源:https://stackoverflow.com/questions/42596609/knitr-chunk-option-eval-true-echo-true-include-false

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!