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

Romain Francois romain.francois at dbmail.com
Mon Mar 16 19:50:59 CET 2009


Duncan Murdoch wrote:
> 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.
Hi Duncan,

It would be pretty easy to use the output from the R parser (which is 
never wrong, is it?), and dump some markup out of it. For example the 
showTree function in codetools dumps an R expression as Lisp, this is 
not too far from generating html, or any other markup.

As this sounds like fun, I'll volunteer to do something about this. 
Another advantage is that we can imagine to plug hyperlinks in  R code 
that lives in html help pages.

Romain

> 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.
>
> ______________________________________________
> 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
http://romainfrancois.blog.free.fr




More information about the R-help mailing list