11

Are there any standard syntax highlighting rules for R? If yes, where can they be found?

Or does each editor, IDE, package (e.g., the highlight package) create their own rule set?

Roland
  • 127,288
  • 10
  • 191
  • 288
  • 2
    +1 have thought about this too, but never had the courage to ask on SO :) – Arun Nov 15 '13 at 11:11
  • +1 and it would be nice to surface your [tag:rstudio] example from [**chat**](http://chat.stackoverflow.com/transcript/message/12961957#12961957) – Simon O'Hanlon Nov 15 '13 at 11:12
  • Not that I know of. I searched around a bit, while putting together my tk script editor package [rite](https://github.com/leeper/rite), and didn't find anything...I basically tried to copy the apparent formatting rules provided by Notepad++ (without complete success). – Thomas Nov 15 '13 at 11:35
  • 3
    @SimonO101 I just found that there is an r_highlight.html file in my RStudio installation that apparently defines the highlighting with java script and some regex. – Roland Nov 15 '13 at 11:59
  • ACE code editor has a syntax mode file for R that you can reference. https://github.com/ajaxorg/ace-builds/blob/master/src/mode-r.js – mccainz Nov 15 '13 at 13:58

1 Answers1

12

Each editor creates their own rule set. For historical reasons, each editor has implemented syntax highlighting in its own way. Having a cross-editor standard may be possible using, for example, GeSHi, but it would almost certainly require a lot of effort getting editor makers to sign up to it, especially if they already have their own system.

Eclipse uses .hrc files for storing syntax information.
RStudio has a file called r_highlight.html.
Notepad++ stores keywords for different languages in a file named langs.model.xml.
Textpad has its own .syn format for the code highlighting.
TextWrangler has a plugin.

Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
  • There's a plugin for TextWrangler, for you OSX users. https://files.nyu.edu/jmb736/public/code/R_language_module_for_BBEdit/R.plist Oh, and SciTe has an R ruleset, too. – Carl Witthoft Nov 15 '13 at 12:34
  • 1
    There's also the highlight package if you want to do it from R code – hadley Nov 15 '13 at 18:25