[Rd] pattern in history

From: Romain Francois <francoisromain_at_free.fr>
Date: Tue 11 Apr 2006 - 09:00:12 GMT


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 |
+---------------------------------------------------------------+ ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Tue Apr 11 19:24:55 2006

This archive was generated by hypermail 2.1.8 : Tue 11 Apr 2006 - 14:17:00 GMT