I have functions f1
and f2
that are taking a function as argument, eg:
f1 <- function(FUN) {
...
}
f2 <- function(FUN) {
f1(FUN=FUN)
}
From inside function f1
, I need to find back the original name of the function passed to f2
, eg "myFunc"
, but not "FUN"
.
Basically can we imagine a function f1
so that f2(f1(mean))
returns "mean"
? If FUN
is anonymous, we can for instance return NULL
or NA
.
Is there an easy / standard way to do that in R? I have tried to manually search for identical function code using (but it is not very clean and I am looking for a better solution)
fn = unlist(as.list(lsf.str(envir=.GlobalEnv)))
for (f in fn) {
if (setequal(paste(body(myFunc)),paste(body(f)))) {
return(f)
}
}