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

Duncan Murdoch murdoch at stats.uwo.ca
Mon Mar 16 19:42:53 CET 2009


On 3/16/2009 1:49 PM, Jose Quesada wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>  
> Hi,
> 
> A follow up to my previous post. It'd be good to have syntax
> highlighting in the html help pages. 

This needs two things:  making the highlight program available to R, and 
then adding it to the Rd to HTML conversion code.  In current releases 
that conversion is done in Perl code, but with R 2.9 an R-based 
converter will be available (but not used by default; too many CRAN 
packages have too many errors in their Rd files, and the new converter 
is more sensitive to such things).  So sometime after 2.9.0 is released, 
it would seem like a reasonable project to modify the conversion to 
allow for syntax highlighting.

One likely complaint is that the highlighting will be inaccurate. 
Typically highlighters just have a list of things they know to be 
important names, they don't actually take scoping rules into account (so 
mean gets highlighted as a built in function even when used as

mean <- (x + y)/2

for example).  So it would be interesting if someone wanted to do the 
work to make a syntax highlighter that was accurate.  I'd say the R core 
work on something like this would be to provide the hook for a user to 
link in their own favourite highlighter; I doubt if we'd want to take on 
the bitching that the inaccurate highlighting would attract.

Duncan Murdoch


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/           
> -----BEGIN PGP SIGNATURE-----
> 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
> -----END PGP SIGNATURE-----
> 
> ______________________________________________
> 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.




More information about the R-help mailing list