如何判断代码是否在knitr/rmarkdown上下文中执行? [英] how to tell if code is executed within a knitr/rmarkdown context?

查看:70
本文介绍了如何判断代码是否在knitr/rmarkdown上下文中执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于一些简单的测试,在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆