钩针编织时间 [英] Hook to time knitr chunks
本文介绍了钩针编织时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想对编织块计时,并记录在LaTeX输出中使用注释渲染它们所花费的时间.
I would like to time knitr chunks and record how long it took to render them using comments in LaTeX output.
我尝试了以下挂钩:
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)))
}
})
它确实会在时序上产生正确的注释,但是问题在于它被包裹在kframe中,这导致LaTeX输出中出现难看的间隙:
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{kframe}
% Chunk rendering time: 12.786 seconds.
\end{kframe}
有没有办法产生未包装的评论?
Is there a way to produce unwrapped comments?
推荐答案
尝试一下:
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}')
}
})
})
这是一个hack.基本上,您是从kframe
环境中转义LaTeX注释的.
It is a hack, though. Basically you escape the LaTeX comment from the kframe
environment.
这篇关于钩针编织时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文