From sfalcon at fhcrc.org  Thu Dec 14 01:38:02 2006
From: sfalcon at fhcrc.org (Seth Falcon)
Date: Wed, 13 Dec 2006 16:38:02 -0800
Subject: [Rd] A possible improvement to apropos
Message-ID: <m2tzzznwgl.fsf@ziti.local>

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
}



[Rd] A possible improvement to apropos
Seth Falcon