[R] R-code in html help pages: syntax highlighting

Romain Francois romain.francois at dbmail.com
Mon Mar 16 19:11:15 CET 2009

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 


Jose Quesada wrote:
> Hash: SHA1
> Hi,
> A follow up to my previous post. It'd be good to have syntax
> highlighting in the html help pages. There is highlight
> (http://www.andre-simon.de/) which seems to be open source. Since code
> is delimited in the help file format, it should not be too difficult
> to run a highlighting program (actually, vim and emacs do this too)
> recursively and pretty-print all the R examples in the entire CRAN.
> Including the highlighter with R, or whatever supplementary tools
> people use to make R html help files could simplify things. I've never
> written docs or released a package, so I may be understimating the
> effort it'd take to get this working.
> Using the r-help gmane archives also leads to plain code.
> This is probably more trouble than it's worth, since there's no
> metadata delimiting a block of code and it might be difficult... but
> grepping through all R-help posts and coloring code would be really
> nice too. Again, this lands straight into 'nice to have, but not
> essential' territory.
> If anyone wants to do this, feel free to.
> Best,
> - -J
> - --
> Jose Quesada, PhD.
> Max Planck Institute,
> Center for Adaptive Behavior and cognition,
> Berlin
> http://www.josequesada.name/           
> Version: GnuPG v1.4.7 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> iQIVAwUBSb6RRGMobUVGH+HKAQI2RxAAijNIj7qlBogc9M6lhQ2Ah1Px29iU/uzS
> 45t5blwNSGVSbAbZF7N7rRcBdn8/c4W8n+oI62nnap0snwLMFW/ynikVNJuBY+XA
> +yNaO5nIJo5SWu60WkcMinm/ysPZ4o4Jdxr1+lGfJ/ceVSTWPWVLb//GN8QElgwT
> Vf0ZQUSqfWczzeVDSDtfMKGTJOz4y60eF5hounA/PkzyUd8RRo1WpEXzJHYsCTI+
> RwBrYZ5Q30cpKLAJQNeiiv8GDtv7QvJl38uRAqBRK5Ec9CGC0brGZquX8UgHi1q1
> 1+NzHSt95E4Y0CKWPS48t+eO58MUE8v69gjLa9DdnhII4tCdAUURuP+AsaFm+hzP
> a7OufMNnh/S8igDmqon0c9W6sJrkDo9DdrZPlu6MFjGQ5SbS6mSfvwSRKVd3RTCN
> 2/+uz0EwBygq1OKS+Z7Z+kx29UR8+bNXOGaPRlsr5CKcwVV9w3FBvEICuDaP75vj
> l0d75+2R+CB/R/e2+dMMRCQY5MNWtYuuqoz3jNws59J+0z5K35usLoaKdB7Ez3D6
> G2CCBKJSrugT0s8OkhX5pcTiU6NUIrq6q8h7JNEeuR0bniFClXlDrAs9iIdNb4PS
> oFpqtNJWPLaicHRMnJdnxPCriHa0lmI3QVoGrf6UFtBAXuiOkFxcHUmTcQczyfOm
> IGyGcgCko3o=
> =djsT
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

Romain Francois
Independent R Consultant
+33(0) 6 28 91 30 30

More information about the R-help mailing list