[R] History pruning
Ken Williams
ken.williams at thomsonreuters.com
Mon Aug 4 16:15:40 CEST 2008
On 8/1/08 1:13 PM, "Richard M. Heiberger" <rmh at temple.edu> wrote:
> I meant 5a 5b 5c. Multiple-line commands are handled correctly.
> What is is doing is looking for "> " and " +" prompts. Anything else
> is removed.
When I said "5c) prune any lines that don't have assignment operators" I
meant to take a sequence like this (to pick a semi-random chunk from my
history log):
-------
df <- data.frame(x=2:9, y=(1:8)^2)
cor(df)
?cor
mad(c(1:9))
?reshape
a <- matrix(1:12, nrow=3)
b <- matrix(2:13, nrow=3)
b <- matrix(4:15, nrow=3)
b <- matrix(2:13, nrow=3)
c <- matrix(4:15, nrow=3)
a
b
c
-------
And turn it into this:
-------
df <- data.frame(x=2:9, y=(1:8)^2)
a <- matrix(1:12, nrow=3)
b <- matrix(2:13, nrow=3)
b <- matrix(4:15, nrow=3)
b <- matrix(2:13, nrow=3)
c <- matrix(4:15, nrow=3)
-------
Obviously I wouldn't *always* want this performed, but selectively it would
be quite nice.
Further, if the dependency graph among variable definitions were computable,
the sequence could be reduced to this:
-------
df <- data.frame(x=2:9, y=(1:8)^2)
a <- matrix(1:12, nrow=3)
b <- matrix(2:13, nrow=3)
c <- matrix(4:15, nrow=3)
-------
Note that the starting point of all of this is a sequence of commands (the
output of savehistory(), so separating commands from output isn't necessary.
I've made a bit of progress on this, hopefully I can get clearance to show
my work soon. It would be nice if this could be hooked into ESS for
selective pruning or something.
-Ken
--
Ken Williams
Research Scientist
The Thomson Reuters Corporation
Eagan, MN
More information about the R-help
mailing list