[R] from function to its name?

Ido M. Tamir tamir at imp.univie.ac.at
Fri Mar 2 15:42:46 CET 2007


Hi,

I can get from a string to a function with this name:

>f1 <- function(x){ mean(x) }

>do.call("f1",list{1:4})
>get("f1")
etc...

But how do I get from a function to its name?

>funcVec <- c(f1,median)

>funcVec
[[1]]
function(x){ mean(x) }
> str(funcVec)
List of 2
 $ :function (x)
  ..- attr(*, "source")= chr "function(x){ mean(x) }"
 $ :function (x, ...)
> deparse(funcVec[1])
[1] "list(function (x) " "{"                  "    mean(x)"
[4] "})"


thank you very much
ido



More information about the R-help mailing list