[R] R Metadata Importer

This spotlight plugin is based on the Lisp Metadata Importer by John Wiseman. The source code is included.

Version 1.1 indexes .Rnw and .Rout files, in addition to .R files (this can be easily changed by removing the appropriate entries from Contents/Info.plist). Works on Tiger and Leopard (but the command mdimport -r plugin doesn't work on Leopard, at least it doesn't work for me).

How does it work

This plugin indexes Rez files (the .R extension is already defined in MacOSX), and also .Rnw and Rout files (new UTIs are defined: org.r-project.sweave and org.r-project.ouput). Files under /Developer/ are ignored (to prevent indexing of those resource files). The attribute kMDItemTextContent is set (to enable full text searching), and a new attribute org_r_project_functions is defined to contain the list of functions in the file (lines of the form <name> = function or <name> <- function).

How to install

Copy the R Metadata Importer.mdimporter file into the /Library/Spotlight folder

How to uninstall

Remove the R Metadata Importer.mdimporter file from the /Library/Spotlight folder

How to test it

  mdimport -d1 <somefile>.R
will index the file, and print the following message:
  (.....) Import '<filename>' type 'public.rez-source' using
  'file://localhost/Library/Spotlight/R%20Metadata%20Importer.mdimporter/'
The command mdls can be used to inspect the metadata associated with a file, the property org_r_project_functions lists the functions defined in the file.

How to index all R files

mdimport -r /Library/Spotlight/R\ Metadata\ Importer.mdimporter

How to search for a function

Command-F in the finder opens a Find window, the menu for attributes includes an Other... entry, you can then type function in the search field to filter out uninteresting attributes.