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

Liaw, Andy andy_liaw at merck.com
Sat Nov 27 17:44:19 CET 2004


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)
}

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Tom Mulholland
> Sent: Friday, November 26, 2004 8:54 PM
> To: Andy Bunn
> Cc: r-help at stat.math.ethz.ch
> Subject: Re: [R] an R function to search on Prof. Baron's site
> 
> 
> 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;for
> mat=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;for
> mat=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:
> > Using this function with 2.0.0 XP and Firefox 1.0 (I've 
> rediscovered the
> > internet) produces a curious result.
> > 
> > 
> >>myString <- RSiteSearch(string = 'Ripley')
> >>myString
> > 
> > [1]
> > 
> "http://finzi.psych.upenn.edu/cgi-bin/htsearch?config=htdigrun
> 1;restrict=Rhe
> > 
> lp00/archive|Rhelp01/archive|Rhelp02a/archive;format=builtin-l
> ong;sort=score
> > ;words=Ripley;matchesperpage=10"
> > 
> >>version
> > 
> >          _
> > 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@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:
> > 
> >>browseURL(myString)
> > 
> > 
> > However, the searches:
> > 
> >>RSiteSearch(string = 'browseURL Firefox')
> >>RSiteSearch(string = 'browseURL Mozilla')
> > 
> > 
> > don't turn up much help! If I change browseURL to use IE 
> then browseURL
> > behaves as expected:
> > 
> > 
> >>browseURL(myString, browser="C:/Program Files/Internet
> > 
> > Explorer/iexplore.exe")
> > 
> > Specifying Firefox explicitly in browseURL doesn't help - 
> It still opens
> > three windows as above (if no browser is open):
> > 
> > 
> >>browseURL(myString, browser="C:/Program Files/Mozilla
> > 
> > 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
> > 
> > 
> > 
> > 
> >>-----Original Message-----
> >>From: r-help-bounces at stat.math.ethz.ch
> >>[mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of Gabor 
> Grothendieck
> >>Sent: Tuesday, November 23, 2004 11:56 PM
> >>To: r-help at stat.math.ethz.ch
> >>Subject: Re: [R] an R function to search on Prof. Baron's site
> >>
> >>
> >>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.
> >>
> >>______________________________________________
> >>R-help at stat.math.ethz.ch mailing list
> >>https://stat.ethz.ch/mailman/listinfo/r-help
> >>PLEASE do read the posting guide!
> >>http://www.R-project.org/posting-guide.html
> >>
> > 
> > 
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> >
> 
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 
>




More information about the R-help mailing list