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

Peter Langfelder peter.langfelder at gmail.com
Thu Aug 30 01:40:43 CEST 2012


On Wed, Aug 29, 2012 at 4:14 PM, William Dunlap <wdunlap at tibco.com> wrote:
> deparse(substitute(fnc)) will get you part way there.
...
> I like to let the user override what substitute might say by
> making a new argument out of it:
>> applyFunc(function(x)x*10, 1:3)
> fnc is function(x) x * 10
> [1] 10 20 30
>> applyFunc(function(x)x*10, 1:3, fncString="Times 10")
> fnc is Times 10
> [1] 10 20 30
> This makes is easier to call your function from another one - you
> can pass the fncString down through a chain of calls.

Thanks, very good suggestions. The function I am writing is of course
much more complicated than the simplistic example.

Peter




More information about the R-help mailing list