[R-SIG-Mac] Spotlight from R

Paul Roebuck roebuck at mdanderson.org
Fri Apr 7 23:55:14 CEST 2006


On Fri, 7 Apr 2006, Jan de Leeuw wrote:

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

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)



More information about the R-SIG-Mac mailing list