Hook to time knitr chunks

后端 未结 1 1912
孤城傲影
孤城傲影 2021-01-18 06:05

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 = S         


        
相关标签:
1条回答
  • 2021-01-18 06:55

    Try this:

    local({
      now = Sys.time()
      knit_hooks$set(timeit = function(before) {
        if (before) {
          now <<- Sys.time()
        } else {
          x = round(Sys.time() - now, digits = 3)
          x = sprintf("%% Chunk rendering time: %s seconds.", x)
          paste('\\end{kframe}\n', x, '\n\\begin{kframe}')
        }
      })
    })
    

    It is a hack, though. Basically you escape the LaTeX comment from the kframe environment.

    0 讨论(0)
提交回复
热议问题