title: Logging console history with errors in R or Rstudio
body: <p>For educational purposes we are logging all commands that students type in the rstudio console during labs. In addition we would like to store if call was successful or raised an error, to identify students which struggling to get the syntax right.</p>
  
  <p>The best I can come up with is something like this:</p>
  
  <pre><code>options(error = function(){
    timestamp("USER ERROR", quiet = TRUE)
  })
  </code></pre>
  
  <p>This adds an <code>## ERROR</code> comment on the history log when an exception occurs. Thereby we could analyze history files to see which commands were followed by an <code>## ERROR</code> comment.</p>
  
  <p>However R's internal history system is not well suited for logging because it is in-memory, limited size and needs to be stored manually with <code>savehistory()</code>. Also I would prefer to store log one-line-per-call, i.e. escape linebreaks for multi-line commands.</p>
  
  <p>Is there perhaps a hook or in the R or RStudio console for logging actual executed commands? That would allow me to insert each evaluated expression (and error) in a database along with a username and timestamp.</p>