R-code in html help pages: syntax highlighting
Romain Francois wrote:
Duncan Murdoch wrote:
That is an issue. I guess I will fall back on what the parser says and
infer on the scoping. Within the lines below, mean would be different
each time
mean( 1:10 )
lapply( 1:10, mean)
mean <- (1+4) / 2
lapply( list( mean, median), function( f ) f( 1:10) )
{ mean <- median; mean( 1:10 ) }
So if you've got high standards, it's probably quite hard. On the other hand, if you're willing to accept the usual sort of errors that syntax highlighters make, it's not so bad, but not trivial.
it would be good to know what you mean by 'errors'. syntax highlighters are, in principle, *syntax* highlighters. in the example above, the first and sixth occurrences of 'mean' are in the operator position, the others are not -- would it be *syntactically* inappropriate to color-code the former in one way, and the latter in another? why should a *syntax* highlighter care about what's the object referred to by 'mean' in this or other context? otherwise, it would certainly be fun to have a semantic highlighter for r. (..)
(I'd guess it'll be fast enough: Brian Ripley reported that all the R code he wrote for conversions in R-devel was faster than the Perl code it was replacing.)
the 'benchmark' you are talking about is only as good as the perl scripts were. i have had a look at a couple of perl scripts in the r sources, and it seemed like there was quite some space for improvement. vQ