[R] Mapping function dependencies

David Khabie-Zeitoune dave at evocapital.com
Wed Aug 13 15:11:00 CEST 2003


With regards to my question below, I've found a way to do it:

all.names(body(test))

Seems to do the trick. Still, if there are any tools already developed
for mapping the dependencies between a set of functions I be very
interested to hear before I reinvent the wheel.

Thanks,
Dave


-----Original Message-----
From: David Khabie-Zeitoune 
Sent: 13 August 2003 14:01
To: r-help at stat.math.ethz.ch
Subject: [R] Mapping function dependencies


Hi

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))
> all.names(expression(test))
 [1] "test"

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 +
y))))
> tmp
 [1] "function" "return"   "*"        "sin"      "+"        "x"       
 [7] "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))
else FALSE)
> tmp[pos.fn]
 [1] "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.

David

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help




More information about the R-help mailing list