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

Peter Langfelder peter.langfelder at gmail.com
Thu Aug 30 01:00:14 CEST 2012


On Wed, Aug 29, 2012 at 3:36 PM, Peter Langfelder
<peter.langfelder at gmail.com> wrote:
> Hi all,
>
> is there a way to extract the name of a function, i.e. do the reverse
> of match.fun applied to a character string? I would like to print out
> the name of a function supplied to another function as an argument.
>
> For example:
>
> myFunc = function(x) { x+1 }
>
> applyFunc = function(fnc, x)
> {
>   fnc = match.fun(fnc)
>   fnc(x)
> }
>
> Is there a way to obtain "myFunc" from the argument fnc in applyFnc
> the following call is issued?
>
> applyFnc(myFunc, 1)

...or am I missing the basic fact that since arguments to functions in
R are passed by copy, the name is lost/meaningless?

Thanks,

Peter




More information about the R-help mailing list