2015-05-29 56 views
5

我想要時間編織塊並記錄需要多長時間才能在LaTeX輸出中使用註釋來呈現它們。鉤到時間knitr塊

我已經試過以下鉤:

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輸出:

\begin{kframe} 

% Chunk rendering time: 12.786 seconds. 

\end{kframe} 

有沒有辦法產生未包裝的評論?

+0

FWIW,它被交叉發佈在https://github.com/yihui/knitr/issues/1042 –

+0

你有MWE指示_ugly gaps_? – Thell

回答

3

試試這個:

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

這是一個黑客,但。基本上你逃過了kframe環境的LaTeX評論。