Suppose that we have an .Rmd
(or .Rnw
) document and and an R
module, which are connected via read_chunk()
. In the R
module, we would like to have an ability to check the run-time status of knitr
, in other words, to verify whether execution of the module's code chunks occurs under knitr
's control, or it's a simple R
session. How this could be done? I thought about initializing a global flag in the first code chunk, where knitr
gets loaded, but I'm not sure, if it's the best solution and even whether it would work.
UPDATE:
I just verified my global variable approach and it didn't work. Not sure whether I'm doing something wrong, or I don't understand the mechanics of knitr
's loading and initialization. I have done the following: simply initialized the flag to FALSE
in the beginning of an R
module and then reset the flag to TRUE
in the first chunk in .Rmd
document, where knitr
gets loaded. Then I placed print()
statement somewhere in the R
module and ran it as R
session and via processing .Rmd
document. Regardless, it prints FALSE
.