Hook to time cut the pieces

I would like time to cut the pieces and write down how long it took to make them using the comments in the LaTeX output.

I 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 gives the correct comment with synchronization, but the problem is that it is completed in kframe, which leads to ugly gaps in LaTeX output:

 \begin{kframe} % Chunk rendering time: 12.786 seconds. \end{kframe} 

Is there a way to create detailed comments?

+5
source share
1 answer

Try the following:

 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}') } }) }) 

This is a hack. Basically you avoid LaTeX comment from kframe environment.

+3
source

All Articles