Skip to content
Prev 59952 / 398502 Next

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

Thanks to Tom and Andy for pointing this out and chasing it down.  I tried
replacing "|" by "%7C" and that seems to fix the problem (at least on a
somewhat outdated release of Firefox).  Please let me know if the following
works.

With regard to Gabor's comment:  I'd guess R-core would be reluctant to have
functions in base that depends on something outside the official R site, the
excellent service that Prof. Baron provide not withstanding.  Although I'd
vote for suggesting the use of these in the FAQ or the R-help posting guide.

Best,
Andy

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%7CRhelp01/archive%7CRhelp02a/archive",
                  "finzi.psych.upenn.edu/R/doc",
                  "finzi.psych.upenn.edu/R/library",
 
"finzi.psych.upenn.edu/R/doc%7Cfinzi.psych.upenn.edu/R/library")
    res <- paste("restrict=", res, sep="")
    qstring <- paste(qstring, res, format, sortby, string, mpp, sep=";")
    browseURL(qstring)
    invisible(qstring)
}