[Rd] A possible improvement to apropos

Seth Falcon sfalcon at fhcrc.org
Thu Dec 14 01:38:02 CET 2006


Hello all,

I've had the following apropos alternative in my ~/.Rprofile for some
time, and have found it more useful than the current version.
Basically, my version ignores case when searching.

If others find this useful, perhaps apropos could be suitably patched
(and I'd be willing to create such a patch).

+ seth

Here is my version of apropos:


APROPOS <- function (what, where = FALSE, mode = "any") 
{
    if (!is.character(what))
      stop("argument ", sQuote("what"), " must be a character vector")
    x <- character(0)
    check.mode <- mode != "any"
    for (i in seq(search())) {
        contents <- ls(pos = i, all.names = TRUE)
        found <- grep(what, contents, ignore.case = TRUE, value = TRUE)
        if (length(found)) {
            if (check.mode) {
                found <- found[sapply(found, function(x) {
                    exists(x, where = i, mode = mode, inherits = FALSE)
                })]
            }
            numFound <- length(found)
            x <- c(x, if (where)
                   structure(found, names = rep.int(i, numFound)) else found)
        }
    }
    x
}



More information about the R-devel mailing list