Indeed Highlight is excellent for highlighting program code, however, the definition file for R language is far from complete. Below is the original definition file:
$KW_LIST(kwa)=if else repeat while function for in next break
$KW_LIST(kwb)=NULL NA Inf NaN
$STRINGDELIMITERS=" '
$SL_COMMENT=#
$ESCCHAR=\
$SYMBOLS= ( ) [ ] { } , ; : & | < > ! = / * % + -
Certainly, what we still need are those thousands of keywords in R, most of which are functions. Thus how can we get the names of functions in the packages of R? The solution is actually quite easy — just use ls() with the environment name specified. The following is my source code for picking out the names of functions in all packages which are in the search path:
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()
The rest of work is just copy the result, and then paste them into the file “r.lang” (in directory “langDefs“) as $KW_LIST(kwc). Finally the definition codes are just like:
$KW_LIST(kwa)=if else repeat while function for in next break ifelse switch
$KW_LIST(kwb)=NULL NA Inf NaN TRUE T FALSE F
$KW_LIST(kwc)=acf acf2AR add.scope add1 addmargins aggregate ...
$STRINGDELIMITERS=" '
$SL_COMMENT=# $ESCCHAR=\
$SYMBOLS= ( ) [ ] { } , ; : & | < > ! ?= / * % ?+ -
You may download the definition file here (updated on Oct 2, 2007):
Downdload the file hereJust copy it to the directory “langDefs” and override the original one, then Highlight can convert files like what you see in my blogs. Sure, you need CSS definitions to make the code more beautiful and pleasant, and my CSS file is here: highlight-r.css
At last, I’d like to thank André Simon for his help and suggestions for the improvements of this definition file.
Hi guyz! I'm really have no idea how to solve problem that ask for width of each interval, which it is consist of 6 interval. Can you tell me?
Sorry, but I don't understand your question…