I’ve been using the R language for some years now but didn’t have it installed on my current machine.
TextMate is a great editor to use as it has a custom bundle that gives you syntax highlighting and executes commands for you in the R console.
To install the R bundle:
cd ~/Library/Application\ Support/TextMate/Bundles/ svn co http://svn.textmate.org/trunk/Bundles/R.tmbundle/
Then in TextMate choose Bundles->Bundle Editor->Reload Bundles.
There is one tweak I make which is that I like to press ⌘ + RETURN to execute the current selection in the R console. So edit the bundle and find R.app in the commands and change the key. Also I like it to return back to text mate afterwards, so I add the following to the script:
-e ‘tell application “TextMate” to activate’ \
I also removed the line about setting the current dir. This was a little fiddly – I found that I had to make sure I selected the entire line and cut it then delete, making sure there are no end of line characters. So it looks like this:
# input is selection or document rawText=”`cat`” curDir=” if [[ ${#TM_DIRECTORY} -gt 0 ]]; then curDir=”$TM_DIRECTORY” fi osascript -e ‘on run(theCode)’ \ -e ‘tell application “R” to activate’ \ -e ‘tell application “R” to cmd (item 1 of theCode)’ \ -e ‘tell application “TextMate” to activate’ \ -e ‘end run’ — “$rawText” “$curDir”
All good.
UPDATE: 07/02/2011 – R now comes with a 64bit version so if you are on a macbook you can replace “R” in the code above with “R64”