Quantcast

Finding inter-function dependencies within a package

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Finding inter-function dependencies within a package

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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Finding inter-function dependencies within a package

Rainer M Krug-6
On Thu, Sep 29, 2011 at 1:11 PM, Keith Jewell <[hidden email]>wrote:

> 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 :-(
>

Roxygen had the functionality to draw dependency graphs - but I think it has
been excluded in Roxygen2?

Rainer



> 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
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



--
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology,
UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :       +33 - (0)9 53 10 27 44
Cell:       +33 - (0)6 85 62 59 98
Fax (F):       +33 - (0)9 58 10 27 44

Fax (D):    +49 - (0)3 21 21 25 22 44

email:      [hidden email]

Skype:      RMkrug

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Finding inter-function dependencies within a package

Duncan Murdoch-2
In reply to this post by Keith Jewell
On 11-09-29 7:11 AM, Keith Jewell wrote:
> 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?

codetools::findGlobals could be used to do this.

Duncan Murdoch

>
> Thanks in advance,
>
> Keith Jewell
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Finding inter-function dependencies within a package

MarkBravington
In reply to this post by Keith Jewell
Hi Keith

'foodweb' and friends in the 'mvbutils' package should do what you're after.

For example, I just tried this on the 'debug' package:

> ff <- foodweb( where=asNamespace( 'debug'))

> # Now either just eyeball the dependency graph that 'foodweb' produces, or more formally:

> callers.of( 'find.debug.HQ', ff)
 [1] ".end.incarnation"          ".onLoad"                   "bp"                        "check.legality"          
 [5] "debug.eval.guts"           "debug.q"                   "debug.Recall"              "debug.with"              
 [9] "debug.within"              "dismiss.debug.window"      "enact.command.r"           "eval.catching.errors"    
[13] "evaluator"                 "find.active.control.frame" "get.mtraced.callers"       "launch.debug.windows"    
[17] "qqq"                       "set.global.debug.vars"     "stepping"                  "try2"                    

HTH
Mark

--
Mark Bravington
CSIRO Mathematical & Information Sciences
Marine Laboratory
Castray Esplanade
Hobart 7001
TAS

ph (+61) 3 6232 5118
fax (+61) 3 6232 5012
mob (+61) 438 315 623

Keith Jewell wrote:

> 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
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Finding inter-function dependencies within a package

Keith Jewell
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
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Finding inter-function dependencies within a package

Keith Jewell
Following helpful correspondence with Mark Bravington, mvbutils::foodweb and
callers.of can do exactly what I wanted very neatly and easily.

The trick is to use base::asNamespace to see non-exported objects in the
package. base::asNamespace is described as "Internal name space support
functions. Not intended to be called directly" so I'll forgive myself for
not knowing about it previously, and keep an eye open for a more mainstream
way to do the same job. But given that, this does my job perfectly
-----
> library(mvbutils)
> ff <- foodweb( funs=find.funs( asNamespace( 'sensory')), where=
> asNamespace( 'sensory'), prune='CreateMeanFizz')

> callers.of('CreateMeanFizz', ff)

-------

where 'sensory' is the loaded package I want to search, and 'CreateMeanFizz'
is the non-exported function of which I want to find callers.



Very nice!

Thanks Mark!



Keith J


"Keith Jewell" <[hidden email]> wrote in message
news:j64058$unj$[hidden email]...

> 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
>>>
>>> ______________________________________________
>>> [hidden email] mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Loading...