Skip to content
Prev 173950 / 398506 Next

R-code in html help pages: syntax highlighting

Wacek Kusnierczyk wrote:
It would certainly be useful to make a difference between the first one 
(call to the mean function from base) and the last one.

If we have sufficient evidence of where the function lives, it would be 
useful for the syntax highlighter to present this evidence.

I'd like to see function highlighted differently for:
- function in standard R packages
- function exported from the NAMESPACE of the package being highlighted
- function not exported from the NAMESPACE
- function which belongs to a package on which this one depends
 
It makes the job trivial if we just don't care and put all function 
calls to the same basket.

But because of scoping rules, and tricks, there are going to be errors.

f <- function( ){
    assign( "mean", median )
    mean( 1:10)
}

f <- function( ){
    assign( paste("m", "e", "a", "n", sep = ""), median )
    mean( 1:10)
}

f <- function( ){
    eval( parse( text = 'assign( paste("m", "e", "a", "n", sep = ""), 
median )') )
    mean( 1:10)
}

... and so on.