[Rd] pattern in history

Romain Francois francoisromain at free.fr
Tue Apr 11 11:00:12 CEST 2006


Hi,

Sometimes I need to consult the history of commands that are matching a 
regex, so I modified the utils::history function for that purpose. I 
found it useful.

I append the code ( I only added the two lines with #**)

Romain.


history2 <-
function (pattern="", max.show = 25, reverse = FALSE, unique = 
pattern!="", ...)
{
    file1 <- tempfile("Rrawhist")
    savehistory(file1)
    rawhist <- scan(file1, what = "", quiet = TRUE, sep = "\n")
    rawhist <- rawhist[grep(pattern, rawhist, ...)] #**
    if(unique) rawhist <- unique(rawhist) #**
    unlink(file1)
    nlines <- length(rawhist)
   
    inds <- max(1, nlines - max.show):nlines
    if (reverse)
        inds <- rev(inds)
    file2 <- tempfile("hist")
    write(rawhist[inds], file2)
    file.show(file2, title = "R History", delete.file = TRUE)
}


-- 
visit the R Graph Gallery : http://addictedtor.free.fr/graphiques
mixmod 1.7 is released : http://www-math.univ-fcomte.fr/mixmod/index.php
+---------------------------------------------------------------+
| Romain FRANCOIS - http://francoisromain.free.fr               |
| Doctorant INRIA Futurs / EDF                                  |
+---------------------------------------------------------------+



More information about the R-devel mailing list