Skip to content
Prev 245117 / 398503 Next

How to save & play back an entire R session?

To just save a copy of all the commands issued you can use the savehistory function (this is documented on the same page as history, so David's answer would have lead you there as well).  If you want to save all the outputs from you session you can use the sink function.

You can save a combination of the inputs and outputs using the R2HTML package or the TeachingDemos package (see ?txtStart in the later).  For both of those you need to start recording and end recording (and specify if you want a graph saved).  The txtStart option also gives the option to save a script file of all the commands (similar to saveHistory, but as you go along rather than after the fact) that can be rerun later using source.

But it is generally better to write a script file and run from that, then you have control over what goes into the file, do you really want to rerun all calls to help and mistakes?  You can run a whole script from a file using the source function, or there are various editors that will send lines or blocks to be evaluated (the R gui on windows does this, also emacs, tinn-R, vim, and probably others that I missed).