Skip to content

an R function to search on Prof. Baron's site

4 messages · Liaw, Andy, Gabor Grothendieck, Andy Bunn +1 more

#
Inspired by the functions that Barry Rawlingson and Dave Forrest posted for
searching Rwiki and R-help archive, I've made up a function that does the
search on Prof. Baron's site (Thanks to Prof. Baron's help on setting up the
query string!):

RSiteSearch <- function(string, restrict="Rhelp", format="long",
                        sortby="score", matchesPerPage=10) {
    URL <- "http://finzi.psych.upenn.edu/cgi-bin/htsearch"
    qstring <- paste(URL, "?config=htdigrun1", sep="")
    ## replace spaces with "%20" in the query
    string <- paste("words=", gsub(" ", "%20", string), sep="")
    mpp <- paste("matchesperpage=", matchesPerPage, sep="")

    format <- charmatch(format, c("long", "short"))
    if (format == 0) stop("format must be either long or short")
    format <- paste("format=builtin-", switch(format, "long", "short"),
sep="")

    sortby <- charmatch(sortby, c("score", "time", "title", "revtime"))
    if (sortby == 0) stop("wrong sortby specified")
    sortby <- paste("sort=",
                    switch(sortby, "score", "time", "title", "revtime"),
                    sep="")
                    
    res <- charmatch(restrict, c("Rhelp", "doc", "function", "doc/fun"))
    if (res == 0) stop("wrong restriction specified")
    res <- switch(res, "Rhelp00/archive|Rhelp01/archive|Rhelp02a/archive",
                  "finzi.psych.upenn.edu/R/doc",
                  "finzi.psych.upenn.edu/R/library",
 
"finzi.psych.upenn.edu/R/doc|finzi.psych.upenn.edu/R/library")
    res <- paste("restrict=", res, sep="")
    qstring <- paste(qstring, res, format, sortby, string, mpp, sep=";")
    browseURL(qstring)
    invisible(qstring)
}

The options roughly correspond to the options on that search page.  Hope
some people find this somewhat helpful.  Comments/suggestions for
improvement are much appreciated.

Best,
Andy
#
Liaw, Andy <andy_liaw <at> merck.com> writes:

: 
: Inspired by the functions that Barry Rawlingson and Dave Forrest posted for
: searching Rwiki and R-help archive, I've made up a function that does the
: search on Prof. Baron's site (Thanks to Prof. Baron's help on setting up the
: query string!):

It would be nice if this and the other search functions recently
posted were collected into a package or even integrated into
R itself.  In the case of the Windows Rgui, it would be nice if they 
appeared on a menu with the other search and help functions.
#
Using this function with 2.0.0 XP and Firefox 1.0 (I've rediscovered the
internet) produces a curious result.
[1]
"http://finzi.psych.upenn.edu/cgi-bin/htsearch?config=htdigrun1;restrict=Rhe
lp00/archive|Rhelp01/archive|Rhelp02a/archive;format=builtin-long;sort=score
;words=Ripley;matchesperpage=10"
_
platform i386-pc-mingw32
arch     i386
os       mingw32
system   i386, mingw32
status
major    2
minor    0.0
year     2004
month    10
day      04
language R

If no browser is open, then this is the URL that is browsed in Firefox:
http://finzi.psych.upenn.edu/cgi-bin/htsearch?config=htdigrun1;restrict=Rhel
p00/archive

Oddly, these two other windows are opened too:
http://finzi.psych.upenn.edu/R/Rhelp01/archive/1000.html

and:
http://www.mail-archive.com/r-help at stat.math.ethz.ch/msg17461.html

This happens regardless of what the search string is. If a browser window is
open then everything works as planned. The sticky bit, obviously, is parsing
browseURL which has the same behavior if I try:
However, the searches:
don't turn up much help! If I change browseURL to use IE then browseURL
behaves as expected:
Explorer/iexplore.exe")

Specifying Firefox explicitly in browseURL doesn't help - It still opens
three windows as above (if no browser is open):
Firefox/firefox.exe")

So, under Windows the 'NULL' argument in 'browser' which determines the
browser via file association isn't the problem.

Anybody know how I can make Firefox work a little more smoothly?

Thanks, Andy
2 days later
#
The problem appears to be associated with the "|"  in 
"Rhelp00/archive|Rhelp01/archive|Rhelp02a/archive". When you run the 
function in Firefox with restrict set to "doc" it gives the right response.

This function eventually uses system. So I decided to see if I could get 
this to work by hand using the code from browseURL

 > cmd
[1] "\"C:/Program Files/Internet Explorer/iexplore.exe\" 
http://finzi.psych.upenn.edu/cgi-bin/htsearch?config=htdigrun1;restrict=Rhelp00/archive|Rhelp01/archive|Rhelp02a/archive;format=builtin-long;sort=score;words=Ripley;matchesperpage=10"
 > system(cmd, wait = FALSE)

Works as expected since it does anyway. I make the assumption that I at 
least have the code correct.

 > cmd
[1] "\"C:/Program Files/Mozilla Firefox/firefox.exe\" 
http://finzi.psych.upenn.edu/cgi-bin/htsearch?config=htdigrun1;restrict=Rhelp00/archive|Rhelp01/archive|Rhelp02a/archive;format=builtin-long;sort=score;words=Ripley;matchesperpage=10"
 > system(cmd, wait = FALSE)

Falls over as previously described

I then thought that maybe quoting the search term would work, but this 
appears not to be the case.

As is noted in ?system "The command is run directly as a Windows command 
by the Windows API call 'CreateProcess'" Who knows what goes on in these 
processes. This is as far as I can go. It looks as if the API connection 
between system and Mozilla does not function the same way as with IE, 
and it is not obvious to me where the problem might be.

Tom Mulholland

R       R version 2.0.1, 2004-11-15
OS.type windows
GUI     Rgui
Andy Bunn wrote: