Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use <code>addTaskCallback</code> as follows to create a log of each top level execution.</p> <pre><code>.log &lt;- data.frame(time=character(0), expr=character(0)) .logger &lt;- function(expr, value, ok, visible) { # formals described in ?addTaskCallback time &lt;- as.character(Sys.time()) expr &lt;- deparse(expr) .log &lt;&lt;- rbind(.log, data.frame(time, expr)) return(TRUE) # required of task callback functions } .save.log &lt;- function() { if (exists('.logger')) write.csv(.log, 'log.csv') } addTaskCallback(.logger) x &lt;- 1:10 y &lt;- mean(x) .save.log() .log # time expr # 1 2013-06-27 12:01:45.837 addTaskCallback(.logger) # 2 2013-06-27 12:01:45.866 x &lt;- 1:10 # 3 2013-06-27 12:01:45.876 y &lt;- mean(x) # 4 2013-06-27 12:01:45.900 .save.log() </code></pre> <p>Of course instead of committing the cardinal sin of growing a <code>data.frame</code> row-wise, as I have here, you could just leave a connection open and write directly to file, closing the connection with <code>on.exit</code>.</p> <p>And if you want to be tidy about it, you can pack the logging setup into a function pretty nicely.</p> <pre><code>.log &lt;- function() { .logger &lt;&lt;- local({ log &lt;- data.frame(time=character(0), expr=character(0)) function(expr, value, ok, visible) { time &lt;- as.character(Sys.time()) expr &lt;- deparse(expr) log &lt;&lt;- rbind(log, data.frame(time, expr)) return(TRUE) } }) invisible(addTaskCallback(.logger)) } .save.log &lt;- function() { if (exists('.logger')) write.csv(environment(.logger)$log, 'log.csv') } .log() x &lt;- 1:10 y &lt;- mean(x) .save.log() </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload