Re: [Rd] Finding inter-function dependencies within a package

From: Keith Jewell <k.jewell_at_campden.co.uk>
Date: Fri, 30 Sep 2011 09:54:48 +0100

Thanks for the suggestions. Just to wrap up this thread...

Rainer Krug pointed out that Roxygen did have dependency graphs, although Roxygen2 doesn't. But I guess (probably wrongly!) that I'd need to process/modify the .R files to use that, and I'm not the package author.

Duncan Murdoch pointed out codetools::findGlobals which can be used to find functions called by a target function. But I want to find functions calling a target function.

Mark Bravington pointed out mvbutils::foodweb and callers.of which almost do what I want (I think it was this I half remembered). But this works in the namespace of the package, and my target function isn't exported so foodweb doesn't see it!

Working from Duncan's suggestion I came up with this, not pretty or fast, could certainly be improved, but it did my one-off job.:



# return a character vector of names of functions in 'tarPack' (character) which directly call the function 'tarFunc' (character) called.by <- function(tarFunc, tarPack){ require(codetools)
flist <- sapply(lsf.str(tarPack, all=TRUE), c) names(flist) <- NULL
gotit <- sapply(flist, function(x) tarFunc %in% findGlobals(get(x, tarPack), FALSE)$functions)
flist[gotit]
}
# e.g.
called.by("CreateMeanFizz", "package:sensory")

Thanks again for the input.

Keith Jewell

>> Hi,
>>
>> I'd like to know which functions in a package call one specific
>> function.
>> I think I've seen a tool for identifying such dependencies, but now I
>> can't find it :-( Searches of help and R site search for keywords
>> like function, call, tree, depend haven't helped :-(
>>
>> Can anyone point me in the right direction?
>>
>> Thanks in advance,
>>
>> Keith Jewell
>>
>> ______________________________________________
>> R-devel_at_r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri 30 Sep 2011 - 09:03:39 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 04 Oct 2011 - 17:10:38 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive