Syntax Highlighting for R scripts?
Posted on

Forums
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
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!
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
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!
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
Log in or register to post comments
great idea mike.
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
http://thebiobucket.blogspot.com/2012/03/r-function-to-read-data-from-google.html
Log in or register to post comments
GeSHi
http://drupal.org/project/geshifilter
Log in or register to post comments