[R] Source code analysis for R ?

Thomas Lumley tlumley at u.washington.edu
Fri May 23 17:56:29 CEST 2003


On Fri, 23 May 2003, Dirk Eddelbuettel wrote:

>
> A GUI-heavy R project of mine has mushroomed into well over 1000 lines of
> code. It is getting to a point where I am wondering if someone had something
> like a script to summarize which functions call which other etc.
>
> Note that I am not looking at profiling but rather a (static) analysis of
> code interdepence.  Does anybody here have anything for this task?
>

This seems to work as a starting point:
calls<-function(fn){
     if(length(fn)==1)
        return(character(0))
     else
        c(as.character(fn[[1]]),sapply(fn, calls),recursive=TRUE)
}

You use it like
 calls(body(update.formula))

             "{"             "<-"    "environment"     "as.formula"

            "<-"      ".Internal" "update.formula"     "as.formula"

    "as.formula"             "<-"        "formula"  "terms.formula"

            "<-"    "environment"         "return"

Unfortunately most of the calls are to <- in any given piece of code, but
it would be easy to trim these out.

Given the links you could then use GraphViz to draw the call graph.

	-thomas




More information about the R-help mailing list