Skip to content

Spotlight from R

2 messages · Jan de Leeuw, Paul Roebuck

#
This is used as

spotlight("correspondence")

It tells you every file (text or pdf or html) in which the
word "correspondence" occurs in $R_HOME/library. This does not just  
search
titles, keywords, and headings in help files, but all files, and the
entire file, using the Spotlight database. It displays the results in
the pager, which in my case is AquaLess. Of course if you search for  
"and"
or "R" you are in trouble, especially with 1000 packages installed.

spotlight<-function(word) {
place<-paste(Sys.getenv("R_HOME"),"/library/",sep="")
string<-paste("mdfind -onlyin",place,word,"|",getOption("pager"))
system(string, intern=TRUE)
}

==========================================================
Jan de Leeuw, 11667 Steinhoff Rd, Frazier Park, CA 93225, 661-245-1725
.mac: jdeleeuw ++++++  aim: deleeuwjan ++++++ skype: j_deleeuw
homepages: http://www.cuddyvalley.org and http://gifi.stat.ucla.edu
==========================================================
                Many nights on the road
       and not dead yet ---
                the end of autumn.       (Basho 1644-1694)
#
On Fri, 7 Apr 2006, Jan de Leeuw wrote:

            
Cool! You could augment that by adding your personal
library(*) to the mix as:

spotlight <- function(word) {
    system(sprintf("mdfind -onlyin %s -onlyin %s %s | %s",
                   file.path(R.home(),
                             "library"),
                   file.path(path.expand("~"),
                             "Library",
                             "R",
                             "library"),
                   word,
                   getOption("pager")),
           intern = TRUE)
}


*) mdfind doesn't take a directory path (as one might
expect) and repeating the 'onlyin' argument augments
the search location rather than overrides. What a unique
implementation...

----------------------------------------------------------
SIGSIG -- signature too long (core dumped)