TextWrangler and R
January 10, 2009 - 18:53

- the syntax highlighting file. Save this file in ~/Library/Application Support/TextWrangler/Language Modules/, and restart TextWrangler. Go to TextWrangler’s preferences -> Languages, and add a new suffix mapping (e.g., .r to R language).
- an applescript to execute the selection in TextWrangler. Put this in ~/Library/Application Support/TextWrangler/Scripts/. You can assign a shortcut by going to the Window menu in TextWrangler, then choose Palettes -> Scripts and assign a shortcut, for instance cmd-return for the same behavior as the built-in R text editor. It either executes your current selection, or the line on which your cursor is. Note: for some versions of TextWrangler, you will have to rename the applescript from .txt to .scpt for TextWrangler to recognize the file (it turns out that you sometimes have to save the file with ‘script editor’, to get TextWrangler to recognize it, thanks Brian!).

Update September 18, 2009:
If you like the scripts above, you might also be interested in:
- a script to automatically set your working directory in R to your TextWrangler document's directory.
- a start-up script for R with a couple of useful function that should've been in R in the first place.

