put tryCatchLog in the knitr evaluate.inline hook
I am recently working on a task to catch any message (TRACE, DEBUG, INFO, WARN, ERROR, or FATAL) in the rmarkdown while rendering it.
My first idea was to put render inside tryCatchLog like tryCatchLog(render("my.rmd")). However, this method cannot get any message within the rmd.
Thus, I came up with the second idea. I try to insert the tryCatchLog in the evaluate.inline knitr::hook setting. I expect every line of code will be evaluated under tryCatchLog.
knitr::knit_hooks$set( evaluate.inline =
function (code, envir = knit_global()) {
v = withVisible(tryCatchLog(eval(parse_only(code), envir = envir))) # add tryCatchLog here
if (v$visible)
knit_print(v$value, inline = TRUE, options = opts_chunk$get())
}
)
Nevertheless, this doesn't work alongside what I expect neither. It seems like the file is knit as usual (no tryCatchLog in the evaluate.inline).
Is that I misunderstand the mechanism of evaluate.inline?
I appreciate any comment or explanation!