From francoisromain at free.fr  Tue Apr 11 11:00:12 2006
From: francoisromain at free.fr (Romain Francois)
Date: Tue, 11 Apr 2006 11:00:12 +0200
Subject: [Rd] pattern in history
Message-ID: <443B701C.20605@free.fr>

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                                  |
+---------------------------------------------------------------+



[Rd] pattern in history
Romain Francois