Syntax Highlighting for R scripts?

When looking at a script, or script snippet, I find it very helpful to see syntax highlighting. I am an addict of highlighting. However, it is difficult to get demo scripts, or script snippets highlighted. One possible solution might be this:
http://alexgorbatchev.com/SyntaxHighlighter/
which currently lacks R support (and its wish list forum has been closed due to spam) but it is customizable. Possibly, building an R highlighter - and particularly one that understands OpenMx functions - would be useful? Or perhaps someone has another solution?
I am thinking that syntax highlighting in the documentation as well as in demo, models/nightly etc might help - as long as one can still cut & paste or download the scripts for use. I wouldn't want that broken.
Kate does this
Assuming you have the R syntax highlighting available then if you export it as HTML it keeps the highlighting. I have not tested this exhaustively and your mileage may vary.
I assume other editors do this too.
Log in or register to post comments
In reply to Kate does this by mdewey
Good point that!
However, I am struggling with getting Textmate to do this happily. With bundles-textmate-create html from selection I only get the following which lacks syntax highlighting (it's lit nicely in the editor itself). So this was why I was looking for a more central OpenMx solution, which would simplify html-tagging, e.g.,
library(OpenMx)
which would have the (possible) advantage of working consistently for users of different editors, systems etc. Textmate formatted code pasted below:
# Load Libraries require(OpenMx) require(statmod) # ----------------------------------------------------------------------------- # Prepare Data depData <- read.table(file='depData.txt',header=TRUE) selvars <- names(depData)[c(10:19)] # ----------------------------------------------------------------------------- # Set up function for analysis nonNormTest <- function (data,nQuadPoints=10,nFactors=1) { # Number of: items; quadrature points; maximum # of thresholds; and factors (1 only at present) nItems <- dim(data)[[2]] nthresh <- vector(mode="integer",nItems)
Log in or register to post comments
In reply to Good point that! by neale
yes, to get it highlighted in tm you need css
library(OpenMx) # which would have the (possible) advantage of working consistently # for users of different editors, systems etc. Textmate formatted code pasted below: # Load Libraries require(OpenMx) require(statmod) # ----------------------------------------------------------------------------- # Prepare Data depData <- read.table(file='depData.txt',header=TRUE) selvars <- names(depData)[c(10:19)] # ----------------------------------------------------------------------------- # Set up function for analysis nonNormTest <- function (data,nQuadPoints=10,nFactors=1) { # Number of: items; quadrature points; maximum # of thresholds; and factors (1 only at present) nItems <- dim(data)[[2]] nthresh <- vector(mode="integer",nItems) }
Log in or register to post comments
In reply to yes, to get it highlighted in tm you need css by tbates
I've installed and enabled
I've installed and enabled the GeShi highlighter on the Wiki.
For example the R code fragment below is now highlighted.
x <- rnorm(100, mean = 2, sd = 3)
plot(x, xlab = "index", main = "Example code")
Log in or register to post comments
In reply to I've installed and enabled by AdminRoss
Brilliant, thank you!
So to clarify, one has to use the tags code and /code with < and > around each to start and stop a code block.
mxOption(NULL, "Number of Threads", omxDetectCores() - 1)
I really like this, although I recognize that the ~6% red-green colorblind men and the small fractions of other colorblindness groups may not view this modification with rose-colored glasses.
Log in or register to post comments
In reply to Brilliant, thank you! by neale
RE: Red/Green issues
Great point about the red/green contrast. We can probably fiddle with the defaults. I'll make some time to look into this week.
Log in or register to post comments
great idea mike.
yes: let's do this here!
The code is on github
https://github.com/alexgorbatchev/SyntaxHighlighter
free hosted version as well
http://alexgorbatchev.com/SyntaxHighlighter/download/
Here's a "brush" for R
http://yihui.name/en/2010/09/syntaxhighlighter-brush-for-the-r-language/
here's an example of it in action
http://xianblog.wordpress.com/2012/02/29/abc-in-roma-r-lab-1/
Log in or register to post comments
In reply to great idea mike. by tbates
jealous
seeing this everywhere lately...
http://thebiobucket.blogspot.com/2012/03/r-function-to-read-data-from-google.html
Log in or register to post comments
GeSHi
Seems like under Drupal, we want to install the GeSHi plugin
http://drupal.org/project/geshifilter
Log in or register to post comments