Skip to content
Prev 304517 / 398503 Next

Extracting the name of a function (inverse of match.fun("myFun"))

On 12-08-29 04:00 PM, Peter Langfelder wrote:
You can pass the function name as a string.

applyFunc = function(fun, x)
{
   fnc = match.fun(fun)
    fnc(x)
    print(fun)
}

applyFunc("myFunc", 1)
[1] "myFunc"

PS : avoid renaming the name of your argument within the function ("fnc 
= match.fun(fnc)").

Cheers,

Eloi