Highlight is a freeware for converting source code to formatted text with syntax highlighting by André Simon; it is released under the terms of the GNU GPL license. It supports more than 100 programming languages, including R. You may download it freely from this page.

I'm using Highlight because it will be far more convenient to read those **boring** (!!!) program codes. The colors and font styles will be of great help to us.

By default the definition file for R in Hightlight is far from complete, but it's very easy to complement the definition, as we only need to define the keywords of R. I've written the detailed method in one of my blog pages here: http://www.yihui.name/en/read.php/6.htm

Actually the extraction of R keywords (mainly funtions) can be easily realized in R itself, and the method I mentioned in the above blog page is just like:

- lst = search()
- lst = lst[grep("package:", lst)]
- ########################################################
- # "package:stats" "package:graphics" "package:grDevices"
- # "package:utils" "package:datasets" "package:methods"
- # "package:base"
- ########################################################
- x = NULL
- for (i in 1:length(lst)) x = c(x, ls(lst[i]))
- y = x[-grep("[]\\\ \\|\\(\\)\\[\\{\\^\\$\\*\\+\\?~#%&=:!/@<>-]",
- x)]
- # remove "functions" with special symbols using regexp
- kw = c("if", "else", "repeat", "while", "function",
- "for", "in", "next", "break", "ifelse", "switch", "NULL",
- "NA", "Inf", "NaN", "TRUE", "T", "FALSE", "F")
- # remove some constants, etc
- for (i in 1:length(kw)) y = y[y != kw[i]]
- sink("c:/func.txt") # save the result
- cat(y, sep = " ") # format the result as highlight needs
- sink()

I have modified the above code and put it in the package 'animation' now: the function *highlight.def()* can dynamically generate such a definition file.

The R definition file for Highlight can also be downloaded there.