[R] function coverage

Ross Boylan ross at biostat.ucsf.edu
Mon Jan 14 22:08:33 CET 2013

Is there an easy way to identify all the functions called as a result of
invoking a function?  Getting the calling hierarchy too would be nice,
but is definitely not essential.

I'm trying to understand someone else's package, which is in a namespace
and has some S3 functions.  I could probably live without tracing the S3
functions.  All the functions I want to trace are in R.  The code passes
functions around as arguments, so that the function being called is not
always obvious from inspection of the source immediately around the

I can imagine a solution that went something like this:
1. identify all functions by searching the sources for xxxx <- function(
(probably only at the left margin, to avoid attempting to trace
functions defined inside of functions).
2. Write a function that wraps another function to record the fact that
it has been called.
3. Somehow replace all functions with their wrapped equivalents.
4. make the top level call.
5. inspect the data constructed by the wrapper.

The code is recursive and iterative; manual stepping does not seem
feasible.  The package includes a lot of earlier versions of the code,
and so I suspect that a lot of the code is not active.

Ross Boylan

More information about the R-help mailing list