From k.jewell at campden.co.uk  Fri Sep 30 10:54:48 2011
From: k.jewell at campden.co.uk (Keith Jewell)
Date: Fri, 30 Sep 2011 09:54:48 +0100
Subject: [Rd] Finding inter-function dependencies within a package
References: <j61jp4$esl$1@dough.gmane.org>
	<3D59DF35E7CF3E42BA70C23BD5CBE6A85F5BD9F884@exvic-mbx04.nexus.csiro.au>
Message-ID: <j64058$unj$1@dough.gmane.org>

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



[Rd] Finding inter-function dependencies within a package
Keith Jewell