[R] Mapping function dependencies
dave at evocapital.com
Wed Aug 13 15:00:49 CEST 2003
Does anyone know of any automatic way of mapping out the dependencies of
a function -- i.e. automatically listing which other functions that
function calls? I tried using all.names or all.vars, but I can't get it
to work on a function: e.g.
> test = function(x, y) return(sin(x + y)*cos(x + y))
I guess the problem is that all.names is not being applied to the body
of the function, whereas if I write the function definition out
explicitly in the expression, I can readily get what I want:
> tmp = all.names(expression(function(x, y) return(sin(x + y)*cos(x +
 "function" "return" "*" "sin" "+" "x"
 "y" "cos" "+" "x" "y"
and further process this to get the functional dependencies
> pos.fn = sapply(tmp,function(.x) if (exists(.x)) is.function(get(.x))
 "function" "return" "*" "sin" "+" "cos"
However, this relies on writing out the function definition explicitly
out in the expression which I cannot do as I wish to map the
dependencies of large complex functions.
Thanks for your help.
More information about the R-help