Using TextMate with R

rlogo

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″

Share

Oracle Jdbc Driver 10.2.0.2.0 fails to render Euro (€) when db is set to WE8MSWIN1252 encoding

We just spent a few glorious hours or so trawling the internet and writing old skool jdbc code, to discover this little beauty. Simply upgrade to 10.2.0.5 of the jdbc driver and it goes away.

Thanks to this post http://efreedom.com/Question/1-377745/Oracle-JDBC-Euro-Character we discovered our problem.

For the full details on the euro….

http://www.fileformat.info/info/unicode/char/20ac/index.htm

And if your really bored:

http://www.fileformat.info/info/unicode/char/1f47e/index.htm

Share

Visualise your ANT build with Grand

Ever had the feeling that your build file was a tad complex?

The above is a visualisation provided by the excellent program grand. This particular build script utilises the ASL ant library. I think it might need some love.

Producing the visualisation is very easy. Simply download the jar file and then some ant scripting…

You need to have GraphViz installed which should give you a command line program called “dot”. You can simply try :

dot –help

On the command line to see if you have it installed.

I have a working version on github

Share

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

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.

Share