[R] function coverage

R. Michael Weylandt michael.weylandt at gmail.com
Mon Jan 14 22:19:40 CET 2013


Possibly you could trace() all the functions you're interested in. E.g.,

lapply(ls("package:stats"), trace) # Untested.

MW

On Mon, Jan 14, 2013 at 9:08 PM, Ross Boylan <ross at biostat.ucsf.edu> wrote:
> 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
> call.
>
> 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.
>
> Thanks.
> Ross Boylan
>
> ______________________________________________
> 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.



More information about the R-help mailing list