On Fri, Mar 02, 2007 at 03:42:46PM +0100, Ido M. Tamir wrote: > 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] "})" >
for any symbol/name deparse(substitute(f1)) yields the string representation, but this won't give you "f1" for deparse(substitute(funcVec[1])). but rather the string "funcVec[1]". if you actually want to access funcVec components via strings denoting the components, maybe you simply could use funcVec <- list(f1 = f1, median = median) and access these via funcVec[["f1"]] which would enable using a string variable holding the name: dum = "f1" funcVec[[dum]] hth joerg ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.