如何判断代码是否在knitr/rmarkdown上下文中执行? [英] how to tell if code is executed within a knitr/rmarkdown context?
问题描述
基于一些简单的测试,在rmarkdown::render()
或knitr::knit2html()
中运行代码时,interactive()
为true.也就是说,一个简单的.rmd
文件包含
Based on some simple tests, interactive()
is true when running code within rmarkdown::render()
or knitr::knit2html()
. That is, a simple .rmd
file containing
```{r}
print(interactive())
```
提供一个报告TRUE
的HTML文件.
gives an HTML file that reports TRUE
.
有人知道我可以在一个代码块中运行一个测试,该代码块将确定它是非交互式"运行的吗,我的意思是在knit2html()或render()内"?
Does anyone know of a test I can run within a code chunk that will determine whether it is being run "non-interactively", by which I mean "within knit2html() or render()"?
推荐答案
如 Yihui在github上建议
As Yihui suggested on github isTRUE(getOption('knitr.in.progress'))
can be used to detect whether code is being knitted or executed interactively.
这篇关于如何判断代码是否在knitr/rmarkdown上下文中执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!