Using TextMate with R


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

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 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
if [[ ${#TM_DIRECTORY} -gt 0 ]]; then
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”


Typing the pound, or hash (#) key in emacs on Uk Macbook

My first foray into customising emacs that didn’t involve copy and paste from something on the internet.

The problem with OS X and the uk keyboard is that the pound key actually has a £ on it. To get “#” you have to press alt+3

Of course, in emacs, the alt key is the meta key which is trapped by emacs. The simple function above inserted into your .emacs file should map the keys correctly.

Another option would be to re-map the apple key to be the meta key, perhaps another yak.

For copy and paste-ability:

;; Allow hash to be entered
(defun insert-pound ()
  “Inserts a pound into the buffer”
  (insert “#”))
(global-set-key (kbd “M-3”) ‘(lambda()(interactive)(insert-pound)))

Windows: Anti-aliased fonts don’t work

I was recently installing a new machine and getting a strange feeling that something was awry with my IntelliJ fonts. They looked like they were not being anti-aliased, even though I had checked the correct option. Also I noticed that generally fonts were looking a bit ropey.

After some puzzling I discovered the dialog above. If you right click on the desktop then to properties->appearance->effects… you will see it and you need to make sure the font smoothing is checked.

Phew, now I have beautiful code again.


Installing JRuby with Intellij (OS X)

GET it from

There is a download page, download and exract the tar file somehwere.

I put it in /System/Library/Frameworks/JRuby.framework/jruby-1.5.1

I then created a symbolic link to jruby_current

ln -s jruby-1.5.1/ jruby_current

And then simply add it to my ~/.bash_profile

$vi ~/.bash_profile
export PATH=/System/Library/Frameworks/JRuby.framework/jruby_current/bin:$PATH
#Reload the profile…
$. ~/.bash_profile
#Try out jruby…
$jruby -v
jruby 1.5.1 (ruby 1.8.7 patchlevel 249) (2010-06-06 f3a3480) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_17) [x86_64-java]

Now you can add the JRuby SDK to your Java Module in Intellij:

Now you can have ruby and Java in the same project. Awesome.