Skip to content
Prev 173875 / 398503 Next

R-code in html help pages: syntax highlighting

Hi Jose,

highlight is fairly easy to use from command line. I have something like 
this when I use R from a console that supports color characters:

highlight <- function( fun ){
  fun <- match.fun( fun )
  tf <- tempfile()
  dump( "fun", tf )
  system( sprintf( "highlight -A -S R %s", tf ) )
  unlink( tf )
}

R> highlight( glm )

Replace "-A" with "-f -H" and you have html output ready for pasting 
into a blog or whatever.

See also ?file for how you might want to send the generated output to 
the clipboard, so that you only have Control + V to type on the web 
browser.

Romain
Jose Quesada wrote: