Function dependency function

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Function dependency function

Matthew Dowle-4

Hi,

Is there a function taking a function as an argument, which returns all the
functions it calls, and all the the functions those functions call, and so
on?    I could use Rprof, but that would involve executing the function,
which may miss some branches of code.   I'd really like a function which
looks at the source code to work out all the functions that could possibly
be called.   When I develop a function and release to production environment
(or to some library) then I may need to release other functions I've
developed which that function calls.  As soon as the function call stack
goes outside .GlobalEnv (for example into base) then the search can stop as
I'm only interested in functions in .GlobalEnv  (my own functions).  Also
useful would be the reverse function  i.e.  find all functions which could
possibly call the function.  This could be used to find functions which are
never called and could be considered for deletion.

Thanks,
Matthew



        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Function dependency function

Gabor Grothendieck
This might help:

http://tolstoy.newcastle.edu.au/R/help/05/04/2263.html

On 3/31/06, Matthew Dowle <[hidden email]> wrote:

>
> Hi,
>
> Is there a function taking a function as an argument, which returns all the
> functions it calls, and all the the functions those functions call, and so
> on?    I could use Rprof, but that would involve executing the function,
> which may miss some branches of code.   I'd really like a function which
> looks at the source code to work out all the functions that could possibly
> be called.   When I develop a function and release to production environment
> (or to some library) then I may need to release other functions I've
> developed which that function calls.  As soon as the function call stack
> goes outside .GlobalEnv (for example into base) then the search can stop as
> I'm only interested in functions in .GlobalEnv  (my own functions).  Also
> useful would be the reverse function  i.e.  find all functions which could
> possibly call the function.  This could be used to find functions which are
> never called and could be considered for deletion.
>
> Thanks,
> Matthew
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Function dependency function

Erik Iverson
In reply to this post by Matthew Dowle-4
I had a similar need and found package mvbutils, function foodweb().

 From the help file:

  'foodweb' is applied to a group of functions (e.g. all those in a
      workspace); it produces a graphical display showing the hierarchy
      of which functions call which other ones. This is handy, for
      instance, when you have a great morass of functions in a
      workspace, and want to figure out which ones are meant to be
      called directly. 'callers.of(funs)' and 'callees.of(funs)' show
      which functions directly call, or are called directly by, 'funs'.

Hope that helps,
Erik Iverson

Matthew Dowle wrote:

> Hi,
>
> Is there a function taking a function as an argument, which returns all the
> functions it calls, and all the the functions those functions call, and so
> on?    I could use Rprof, but that would involve executing the function,
> which may miss some branches of code.   I'd really like a function which
> looks at the source code to work out all the functions that could possibly
> be called.   When I develop a function and release to production environment
> (or to some library) then I may need to release other functions I've
> developed which that function calls.  As soon as the function call stack
> goes outside .GlobalEnv (for example into base) then the search can stop as
> I'm only interested in functions in .GlobalEnv  (my own functions).  Also
> useful would be the reverse function  i.e.  find all functions which could
> possibly call the function.  This could be used to find functions which are
> never called and could be considered for deletion.
>
> Thanks,
> Matthew
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Function dependency function

Matthew Dowle-4
In reply to this post by Matthew Dowle-4

That is amazing.

foodweb(prune="<myfunct>") does precisely what I described. It even draws a
graph!

Hats off to the author Mark Bravington.

Thanks Erik for the pointer.

Regards, Matthew


> -----Original Message-----
> From: Erik Iverson [mailto:[hidden email]]
> Sent: 31 March 2006 17:21
> To: Matthew Dowle
> Cc: '[hidden email]'
> Subject: Re: [R] Function dependency function
>
>
> I had a similar need and found package mvbutils, function foodweb().
>
>  From the help file:
>
>   'foodweb' is applied to a group of functions (e.g. all those in a
>       workspace); it produces a graphical display showing the
> hierarchy
>       of which functions call which other ones. This is handy, for
>       instance, when you have a great morass of functions in a
>       workspace, and want to figure out which ones are meant to be
>       called directly. 'callers.of(funs)' and 'callees.of(funs)' show
>       which functions directly call, or are called directly
> by, 'funs'.
>
> Hope that helps,
> Erik Iverson
>
> Matthew Dowle wrote:
> > Hi,
> >
> > Is there a function taking a function as an argument, which returns
> > all the functions it calls, and all the the functions those
> functions call, and so
> > on?    I could use Rprof, but that would involve executing
> the function,
> > which may miss some branches of code.   I'd really like a
> function which
> > looks at the source code to work out all the functions that
> could possibly
> > be called.   When I develop a function and release to
> production environment
> > (or to some library) then I may need to release other
> functions I've
> > developed which that function calls.  As soon as the function call
> > stack goes outside .GlobalEnv (for example into base) then
> the search
> > can stop as I'm only interested in functions in .GlobalEnv  (my own
> > functions).  Also useful would be the reverse function  
> i.e.  find all
> > functions which could possibly call the function.  This
> could be used
> > to find functions which are never called and could be
> considered for
> > deletion.
> >
> > Thanks,
> > Matthew
> >
> >
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> > http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html