title: How to make a log-file of an R-session which combines commands, results and warnings/messages/errors from the R-console
body: <p>I would like to produce a log-file which keeps track of all commands (<em>stdin</em>), results (<em>stdout</em>) and errors/warnings/messages (<em>stderr</em>) in the R console.</p>
  
  <p>I am aware that there are a lot of logging-packages and I tried several like <code>TeachingDemos</code> (seems to ignore stderr completely) or <code>R2HTML</code> (seems to ignore messages), however, none of them seems to include everything from <em>stderr</em>.  </p>
  
  <p>Only <code>knitr</code> and <code>markdown</code> seem to be able to include everything into a single file. But using this workaround, I have to write R-scripts and I cannot freely write commands in the console. <br />Furthermore, I cannot include the <code>knitr</code> or <code>markdown</code> command in the same R-script (which is of course a minor problem).</p>
  
  <p><strong>Here is an example</strong>:</p>
  
  <pre><code>library(TeachingDemos)
  library(R2HTML)    
  library(TraMineR)
  
  logdir &lt;- "mylog.dir"
  
  txtStart(file=paste(logdir,"test.txt", sep=""), commands=TRUE, 
           results=TRUE, append=FALSE)
  HTMLStart(outdir = logdir, file = "test", echo=TRUE, HTMLframe=FALSE)
  
  ## Messages, warnings and errors
  message("Print this message.")
  warning("Beware.")
  "a" + 1
  geterrmessage()
  
  ## Some example application with the TraMiner package 
  ## which uses messages frequently
  data(mvad)
  mvad.seq &lt;- seqdef(mvad[, 17:86])
  mvad.ham &lt;- seqdist(mvad.seq, method="HAM")
  
  txtStop()
  HTMLStop()
  </code></pre>