Based on some simple tests, interactive()
is true when running code within rmarkdown::render()
or knitr::knit2html()
. That is, a simp
A simpler suggestion for rolling your own: see if you can access current chunk options.
```{r, echo = FALSE}
inside_knitr = function() {
length(knitr::opts_current$get()) > 0
}
```
```{r}
inside_knitr()
```
There are, of course, many things you could check. I like the idea of the current chunk options, another possibility is below. I'm not really sure about the pros/cons of either.
```{r}
!is.null(knitr::opts_knit$get("out.format"))
```