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
}
A possible improvement to apropos
9 messages · stefano iacus, Robert Gentleman, Martin Maechler +2 more
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
}
I would second Seth here, because the search is case insensitive but results are not. This is not strictly related to the language. For example, on my shell, the last entries of apropos system are xload(1) - system load average display for X xlogo(1) - X Window System logo xman(1) - Manual page display program for the X Window System which I find a reasonable result. stefano
On 14/dic/06, at 17:45, 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
Martin Maechler <maechler at stat.math.ethz.ch> writes:
Hi Seth, Could you live with typing 'i=T' (i.e. ignore.case=TRUE)?
I can live with my ~/.Rprofile, I suppose. :-)
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
Let me try to argue why I think the default should be case
insensitive.
This is a _search_ function. If you aren't even sure what
something is called, how can you expect to know how it will be
capitalized? Making search functions less likely to return what
the user is looking for seems quite odd to me.
Learning what functions are available has higher precedence, IMO,
than being reminded about case sensitivity. Imagine a user hoping
to find 'getClass' that doesn't always remember case-sensitivity
rules:
apropos("class")
## Doesn't find the function at all.
## Writes a message to R-help without reading the posting guide
APROPOS("class")
## user: "oh, that looks like what I want"
getclass("foo")
## user: "why didn't it work?" ... "ah, maybe I have to spell
## it exactly"
getClass("foo")
## happy user
Remember, the _results_ will be displayed in proper case and a
common next step (should be) to read the man page and possibly try
an example -- especially if a first attempt fails.
Have I made any progress?
Regards,
+ seth
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
"Seth" == Seth Falcon <sfalcon at fhcrc.org>
on Thu, 14 Dec 2006 07:16:30 -0800 writes:
Seth> Martin Maechler <maechler at stat.math.ethz.ch> writes:
>> Hi Seth, Could you live with typing 'i=T' (i.e.
>> ignore.case=TRUE)?
Seth> I can live with my ~/.Rprofile, I suppose. :-)
>> 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
Seth> Let me try to argue why I think the default should be
Seth> case insensitive.
Seth> This is a _search_ function. If you aren't even
Seth> sure what something is called, how can you expect to
Seth> know how it will be capitalized? Making search
Seth> functions less likely to return what the user is
Seth> looking for seems quite odd to me.
okay, okay, yes, you've convinced me.
Thank you (and everyone else) for the feedback!
So the change will be {non-back-compatibly !} to ignore case in
apropos()
For find() -- on the same help page, similar topic --
it's less clear if a change should happen along similar lines.
Changing the *default* there is more problematic, since find()
is used, e.g., in getAnywhere().
I will probably not get to commit my changes before the weekend,
BTW.
Martin
Seth> Learning what functions are available has higher
Seth> precedence, IMO, than being reminded about case
Seth> sensitivity. Imagine a user hoping to find 'getClass'
Seth> that doesn't always remember case-sensitivity rules:
Seth> apropos("class") ## Doesn't find the function
Seth> at all. ## Writes a message to R-help without reading
Seth> the posting guide
Seth> APROPOS("class") ## user: "oh, that looks like
Seth> what I want" getclass("foo") ## user: "why didn't it
Seth> work?" ... "ah, maybe I have to spell ## it exactly"
Seth> getClass("foo") ## happy user
Seth> Remember, the _results_ will be displayed in proper
Seth> case and a common next step (should be) to read the
Seth> man page and possibly try an example -- especially if
Seth> a first attempt fails.
Seth> Have I made any progress?
indeed!
Robert Gentleman writes:
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.
The same design has been employed by help.search for a long time, for exactly the same reasons (albeit with slightly different agrep defaults). -k
Kurt Hornik <Kurt.Hornik at wu-wien.ac.at> writes:
Robert Gentleman writes:
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.
The same design has been employed by help.search for a long time, for exactly the same reasons (albeit with slightly different agrep defaults).
I may not have spent enough time adjusting the behavior, but when I tried agrep for apropos, I found that I almost always got way too many hits and found the case-insensitive grep the right balance. + seth
Seth Falcon writes:
Kurt Hornik <Kurt.Hornik at wu-wien.ac.at> writes:
Robert Gentleman writes:
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.
The same design has been employed by help.search for a long time, for exactly the same reasons (albeit with slightly different agrep defaults).
I may not have spent enough time adjusting the behavior, but when I tried agrep for apropos, I found that I almost always got way too many hits and found the case-insensitive grep the right balance.
Have you tried the help.search design? It uses approximate matching only if the match string is long enough (no less than 5 characters, something slightly larger may be useful for apropos()). -k