[R] Bookmarklet for searching R documentation

Kevin Wright kwright at eskimo.com
Mon Jun 21 22:35:33 CEST 2004


I recently posted a request for a Mozilla search engine plugin for the R 
java search applet.  Having recieved no response, I pursued this myself and 
came up with an alternative.  I found a "bookmarklet" that was used to 
submit searches to Amazon.  I modified the code to submit searches to the R 
search engine.  I tested the following using Firefox 0.9 on Windows 2000.

Create a bookmark called "search R doc" (or whatever) with the following 
text as the "location".  (Note, this is one long line)

javascript:(function(){ function getSearchString (promptString) { s = null;if (document.selection && document.selection.createRange) { s =document.selection.createRange().text; } else if (document.getSelection) { s= document.getSelection(); } if (! (s && s.length)) { s =prompt(promptString,''); } return s; } searchString = getSearchString('Search R help:'); if (searchString != null) { if(searchString.length) { location ='file://c:/R/rw1090/doc/html/search/SearchObject.html?'+escape(searchString); } else { location ='file://c:/R/rw1090/doc/html/search/SearchEngine.html'; } }  })();
 
 
 
Useage notes:

0. Modify the path (in the script) to SearchObject.html and 
SearchString.html depending on your operating system and R version.

1. If text is highlighted when the bookmark is clicked, the selected text 
is submitted to the search engine without any prompt.

2. If no text is selected, a small prompt dialog requests you to enter a 
search string.  Pressing 'enter' will simply open the search page while entering a search word will send the word to the search engine.

3. I prefer to modify one line in the SearchObject.html file so that 
titles, keywords, names are included in the search.  Use this line:
line = line + document.SearchEngine.search (searchstring,true,true,true);
(Note, with a fresh install of R 1.9.0 the only place "SearchObject.html" i
s used is in lattice's lset.html file).  Attention developers: would it 
make sense to modify this file in the CVS tree?  Maybe there is a 
better method for quick searches?

4. The search is a little slow the first time as the java applet loads.

5. Note: Firefox loses hyperlinks when clicking a hyperlink and then 
clicking 'back'.  This has been discussed on the email list.

6. Sit back, relax, and enjoy!  Your mileage may vary, but I like this a lot. 
Thanks to the creator of the original "Search Amazon" bookmarklet.
 
Best,  Kevin Wright




More information about the R-help mailing list