Re: [R] History pruning

From: Greg Snow <Greg.Snow_at_imail.org>
Date: Fri, 08 Aug 2008 12:04:38 -0600

Ken,

Others have given hints on pruning the history, but are you committed to doing this way?

An alternative would be something more like sink, where when you get to a place that you know you want to start saving the commands you run a function to start saving your commands, then at the end you run a command to stop saving the commands. One tool for doing this is in the TeachingDemos package, see the help on ?txtStart.

The main goal of this set of functions was more to save a transcript of a session (including graphical output if you use the etxtStart interface and an external tool), but it has a possible side effect of saving the commands issued in a file that could be 'source'd to rerun the set of commands (which seems similar to what you want). Commands (actually expressions) that result in an error are not included and you can use the txtSkip function to run a command without saving the command in the file (for things like "?plot" that you don't want to rerun). This may give you what you want, or at least something that needs less editing to get at what you want.

Another option would be to take the source code for the above utilities and add some checks that will decide whether to save the command or not (check if an assignment was made, check if any 'par'ameters were changed, etc.).

Another option if you just want some code to recreate the current plot is to look at the plot2script function in the TeachingDemos package. It will create a script (put it on the clipboard by default) to recreate the current plot. It does NOT use the same set of commands that you used to create the plot, but rather lowlevel commands, but it creates a script that you can edit to recreate the plot with just your changes (the current version needs some edits (line wrapping, fixing the box command) before running the script, but it may be another place to start).

Hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow_at_imail.org
(801) 408-8111




> -----Original Message-----
> From: r-help-bounces_at_r-project.org
> [mailto:r-help-bounces_at_r-project.org] On Behalf Of Ken Williams
> Sent: Wednesday, July 30, 2008 12:13 PM
> To: r-help_at_stat.math.ethz.ch
> Subject: [R] History pruning
>
> 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.
>
> --
> Ken Williams
> Research Scientist
> The Thomson Reuters Corporation
> Eagan, MN
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
______________________________________________ R-help_at_r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Received on Fri 08 Aug 2008 - 18:07:28 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 08 Aug 2008 - 20:34:21 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive