[Rd] modifs on ls

From: Romain Francois <rfrancois_at_mango-solutions.com>
Date: Tue 26 Sep 2006 - 16:56:54 GMT


Hi all,

It would be great to be able to use a syntax like :

R> ls("grid:::grid\.")

instead of :

R> ls("package:grid", pattern = "^grid\.")

Here is a modified version of `ls` that does the job. [ The only modifs are just after the if(!missing(name)) ] Does that make sense ?

Cheers,

Romain

ls <- objects <-

    function (name, pos = -1, envir = as.environment(pos), all.names = FALSE,
              pattern)
{

    if (!missing(name)) {

       
        if(length(grep(":::", name))){
           spl <- strsplit(name, ":::")[[1]] 
           name <- paste("package:", spl[1] , sep="")
           pattern  <- paste("^", spl[2], sep="")

}
nameValue <- try(name) if(identical(class(nameValue), "try-error")) { name <- substitute(name) if (!is.character(name)) name <- deparse(name) pos <- name
}
else pos <- nameValue

    }
    all.names <- .Internal(ls(envir, all.names))           

    if (!missing(pattern)) {

       
        if ((ll <- length(grep("[", pattern, fixed=TRUE))) > 0 &&
            ll != length(grep("]", pattern, fixed=TRUE))) {
            if (pattern == "[") {
                pattern <- "\\["
                warning("replaced regular expression pattern '[' by  
'\\\\['")
            }
            else if (length(grep("[^\\\\]\\[<-", pattern) > 0)) {
                pattern <- sub("\\[<-", "\\\\\\[<-", pattern)
                warning("replaced '[<-' by '\\\\[<-' in regular 
expression pattern")
            }

}
grep(pattern, all.names, value = TRUE)
    }
    else all.names
}
-- 
*mangosolutions*
/data analysis that delivers/

Tel   +44 1249 467 467
Fax   +44 1249 467 468

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Wed Sep 27 03:07:18 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 26 Sep 2006 - 17:30:25 GMT.

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