From rgentlem at fhcrc.org  Thu Dec 14 18:56:49 2006
From: rgentlem at fhcrc.org (Robert Gentleman)
Date: Thu, 14 Dec 2006 09:56:49 -0800
Subject: [Rd] A possible improvement to apropos
In-Reply-To: <17793.3882.104712.38161@stat.math.ethz.ch>
References: <m2tzzznwgl.fsf@ziti.local>
	<17793.3882.104712.38161@stat.math.ethz.ch>
Message-ID: <45819061.6030703@fhcrc.org>

I would vastly prefer apropos to be case insensitive by default. The 
point of it is to find things similar to a string, not the same as, and 
given that capitalization in R is somewhat erratic (due to many authors, 
and some of those changing their minds over the years), I find the 
current apropos of little use.

I would also, personally prefer some sort of approximate matching since 
there are different ways to spell some words, and some folks abbreviate 
parts of words.


Martin Maechler wrote:
> Hi Seth,
> 
>>>>>> "Seth" == Seth Falcon <sfalcon at fhcrc.org>
>>>>>>     on Wed, 13 Dec 2006 16:38:02 -0800 writes:
> 
>     Seth> Hello all, I've had the following apropos alternative
>     Seth> in my ~/.Rprofile for some time, and have found it
>     Seth> more useful than the current version.  Basically, my
>     Seth> version ignores case when searching.
> 
>     Seth> If others find this useful, perhaps apropos could be
>     Seth> suitably patched (and I'd be willing to create such a
>     Seth> patch).
> 
> Could you live with typing 'i=T' (i.e.  ignore.case=TRUE)?
> 
> In principle, I'd like to keep the default  as ignore.case=FALSE,
> since we'd really should teach the users that R 
> *is* case sensitive.
> Ignoring case is the exception in the S/R/C world, not the rule
> 
> I have a patch ready which implements your suggestion
> (but not quite with the code below), but as said, not as
> default.
> 
> Martin
> 
>     Seth> + seth
> 
>     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
>>> }
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 

-- 
Robert Gentleman, PhD
Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M2-B876
PO Box 19024
Seattle, Washington 98109-1024
206-667-7700
rgentlem at fhcrc.org



[Rd] A possible improvement to apropos
Robert Gentleman