Hook to time knitr chunks
问题 I would like to time knitr chunks and record how long it took to render them using comments in LaTeX output. I've tried the following hook: now = Sys.time() knit_hooks$set(timeit = function(before) { if (before) { now <<- Sys.time() } else { paste("%", sprintf("Chunk rendering time: %s seconds.\n", round(Sys.time() - now, digits = 3))) } }) And it does produce the correct comment with timing but the problem is that it's wrapped in kframe which results in ugly gaps in the LaTeX output: \begin