[R] searching Jonathan Baron's R Site - revised function

Jonathan Baron
Fri, 24 Dec 2004 12:55:59 -0000

Documentation coming soon.
--
# Written by Andy Liaw and modified by Jonathan Baron 12/24/2004.
RSiteSearch <- function(string,

restrict=c("Rhelp02a","Rhelp01","functions","docs"),
                        format="normal", sortby="score",
matchesPerPage=20) {
    string <-
paste("http://finzi.psych.upenn.edu/cgi-bin/namazu.cgi?query=",
                    gsub(" ", "+", string),
sep="")
    mpp <- paste("max=", matchesPerPage, sep="")

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

    sortby <- charmatch(sortby, c("score", "date:late",
"date:early",
                                  "field:subject:ascending",
"field:subject:decending",
                                  "field:from:ascending",
"field:from:decending",
                                  "field:size:ascending",
"field:size:decending",
                                  "field:uri:ascending",
"field:uri:decending",))
    if (sortby == 0) stop("wrong sortby specified")
    sortby <- paste("sort=",
                    switch(sortby, "score", "date:late",
"date:early",
                                  "field:subject:ascending",
"field:subject:decending",
                                  "field:from:ascending",
"field:from:decending",
                                  "field:size:ascending",
"field:size:decending",
                                  "field:uri:ascending",
"field:uri:decending"),
                    sep="")

    res <- ""
    if ("Rhelp02a" %in% restrict) res <-
"idxname=Rhelp02a"
    if ("Rhelp01" %in% restrict) res <-
paste(res,"idxname=Rhelp01",sep="&")
    if ("docs" %in% restrict) res <-
paste(res,"idxname=docs",sep="&")
    if ("functions" %in% restrict) res <-
paste(res,"idxname=functions",sep="&")
    if (res=="") {print("Using defaults: Rhelp 2002-; functions;
docs.")
      res <-
paste("idxname=Rhelp02a&idxname=functions&idxname=docs",sep="")}
    res <- sub("^&+","",res)

    qstring <- paste(string, mpp, format, sortby, res, sep="&")
    browseURL(qstring)
    invisible(qstring)
}

--
Jonathan Baron, Professor of Psychology, University of Pennsylvania
Home page: http://www.sas.upenn.edu/~baron