[R] History pruning

Marc Schwartz marc_schwartz at comcast.net
Wed Jul 30 20:59:20 CEST 2008


on 07/30/2008 01:12 PM Ken Williams wrote:
> Hi,
> 
> I find that a typical workflow for me looks something like this:
> 
> 1) import some data from files
> 2) mess around with the data for a while
> 3) mess around with plotting for a while
> 4) get a plot or analysis that looks good
> 5) go back through my history to make a list of the shortest command
> sequence to recreate the plot or analysis
> 6) send out that sequence to colleagues, along with the generated plots
> or analysis output
> 
> I wonder if there are any tools people have developed to help with step
> 5.  Typically I do something like this:
> 
> 5a) save my entire history to a text file
> 5b) open it up in Emacs
> 5c) prune any lines that don't have assignment operators
> 5d) prune any plotting commands that were superseded by later plots
> 
> and then start on other more subtle stuff like pruning assignments that
> were later overwritten, unless the later assignments have variable
> overlap between the LHS and the RHS.  Then I just start eyeballing it.
> 
> Would any deeper introspection of the history expressions be feasible,
> e.g. detecting statements that have no side effects, dead ends, etc.
> 
> The holy grail would be something like "show me all the statements that
> contributed to the current plot" or the like.
> 
> Thanks.

I (and many others) use ESS (Emacs Speaks Statistics), in which case, I 
have an R source buffer in the upper frame and an R session in the lower 
frame.

In my particular case, I also happen to use ECB (Emacs Code Browser) 
which also has a left hand column spanning the full vertical length, to 
provide access to other things (file browser, R function and data 
objects, etc.). It also helps integrate Sweave/LaTeX functionality to 
further centralize things and increase productivity. I have also tied in 
Subversion functionality to enable me to engage in version control of my 
code and other key files.

I do all of my editing in the upper frame and use the built-in ESS 
functions to submit the code to the R session. This also provides for 
code syntax highlighting, which makes it easier to visualize code as 
well as to check for things like matching parens/braces, etc.

In this way, your working code (including comments) is kept functionally 
intact in the upper frame and you can edit and use it without having to 
scroll through a long history of commands (which is still there if you 
need it).

More information here:

   http://ess.r-project.org/

HTH,

Marc Schwartz



More information about the R-help mailing list