[R] Summary: html Search Engine not working

david.whiting@ncl.ac.uk david.whiting at ncl.ac.uk
Wed Nov 27 05:16:29 CET 2002

Hi Jarrett, 

(I am a little late joining this thread, but I hope this helps anyway).

An alternative way to search the help system that is not dependent on
Java is help.search().  This is a very fast way to search in the name,
alias, title and keywords fields. This produces a quick list on screen
of matches to the search. What was not immediately obvious to me when I
first used help.search() is that it produces an object which also
includes the URL to the help file (it *is* obvious if you read the help
file as I did... eventually :).  I like using text browsers (like lynx,
links and especially w3m) for their speed and have written a little
function that takes the output of help.search() and makes a webpage with
links to the relevant help files.  I have just made a slight change so
that the default R web browser can be used instead of a text browser -
see the code below. I have only used this on Linux but I hope it should
work on other platforms without too much work. I hope I'm not breaking
too many HTML and R conventions, but this is just meant to be a simple,
fast hack that seems to work for me.

I have set up the defaults for using a text browser (w3m in an xvt
terminal) so to use it you would do something like this:

## Search for "t-test" and display the results using w3m in 
## an xvt terminal:


## Search for "t-test" and display using the default browser:

rfind("t-test", use.text = FALSE) 

Obviously you could make use.text.browser = FALSE the default setting in
the function and then you could just use rfind("t-test") and display in
the results your default brower.



## Some code to help with help. It takes the output of help.search()
## and makes a simple webpage with links to the relevant
## documentation.
## David Whiting.

rfind <- function (search.expr, browser = getOption("browser"),
                   use.text.browser = TRUE,
                   text.browser = "w3m", term = "xvt") {
  ## Conduct the search	and see how many results we get
  search.results <- help.search(search.expr)
  num.results <- length(search.results$matches) / 4

  ## Create the header of the output webpage
  header <- paste("<H1 align=center> Results of search for: ", search.expr,
                  "</H1><H2 align=center> Found ", num.results,
                  " matches. </H2>")
  output.file <- paste(tempdir(), "/rfind.html", sep="")
  cat(header, file = output.file, append = FALSE)
  ## Insert the contents into the webpage
  for (i in 1:num.results) {
    search.expr <- paste("<a href=", 
    			 search.results$matches[i,4], "/",
                         search.results$matches[i,3], "/html/",
                         search.results$matches[i,1], ".html", ">",
                         search.results$matches[i,2], "</a><br>",
                         sep = "")
    cat(search.expr, file = output.file, append = TRUE)

  ## Display the webpage.
  if (use.text.browser) {
    system(paste(term , " -e ", text.browser, output.file, " & "))
  } else {
    browseURL(output.file, browser)}

On Fri, Nov 22, 2002 at 11:36:30AM -0500, jarrett at duke.edu wrote:
> Hi All,
> Yesterday I sent a message about the html Search Engine not working
> properly.  I repeat that message below.  I received some suggestions that
> I should have Java running.  I take that to mean that I have "enabled"
> Java in the preferences list inside Mozilla.  Yes, it's "running", or so
> it appears.  I also opened (not from within R) the html help files using
> Internet Explorer 5.2 (Mac OS X) and experienced the same problem with the
> search engine html page in R not working, and, yes, Java is indicated as
> enabled.  So, initial evidence seems to indicate that the solution is not
> so simple as to have Java running.  Still, I am not so savvy about these
> things that the solution could not be this simple.  So, other suggestions
> are appreciated.  Thanks!
David Whiting

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list