[R] from function to its name?

Charilaos Skiadas skiadas at hanover.edu
Fri Mar 2 16:33:44 CET 2007


On Mar 2, 2007, at 9:42 AM, 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) }

I suppose you could do:

"funcVec"

but that's probably not what you want ;).

Can you do this with any object in R?
In what situation will you be wanting this name? I mean, how would  
you be given this object, but not know its name in advance? If it is  
passed as an argument in a function or something, then what would you  
consider to be its name?
I.e. I don't really see where you would reasonably want to do  
something like this, without there being another way around it.

Btw, perhaps this does what you want:

as.character(quote(f))

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College



More information about the R-help mailing list