Skip to content
Prev 22837 / 63424 Next

Retrieving function name

"Tom McCallum" <tom.mccallum at levelelimited.com> writes:
Depending on what you really want, this is either impossible or
trivial. The trivial version is 

f <- function(x) print(deparse(substitute(x)))

and the impossible one is to get something that prints "mean" if you
do something like

x<-1
f(switch(x, 1 = mean, 2 = median, 3 = sd, 4 = IQR))

or 

g <- function(foo) f(foo)
g(mean)

or indeed does anything sensible with

f(function(x,y) x*y)


Thing is, functions do not "have names", they can be anonymous or
assigned to multiple names, or be passed as arguments.