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

Liaw, Andy andy_liaw at merck.com
Wed Nov 24 04:57:25 CET 2004


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




More information about the R-help mailing list