[R] How to get the function names
Søren Højsgaard
Soren.Hojsgaard at agrsci.dk
Thu Oct 5 22:41:05 CEST 2006
I've defined the function
getFunNames <- function(FUN){
if (!is.list(FUN))
fun.names <- paste(deparse(substitute(FUN)), collapse = " ")
else
fun.names <- unlist(lapply(substitute(FUN)[-1], function(a) paste(a)))
fun.names
}
which gives what I want :
> getFunNames(mean)
[1] "mean"
> getFunNames(ff)
[1] "ff"
> getFunNames(c(mean,ff))
[1] "mean" "ff"
If I call this within a function, things go wrong:
1] "FUN"
> foo(ff)
[1] "FUN"
> foo(c(mean,ff))
Error in substitute(FUN)[-1] : object is not subsettable
Obviously there are some things (quite a few things) which I have not understood. Can anyone help?
Thanks
Søren
More information about the R-help
mailing list