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

2012-08-29 Thread Peter Langfelder
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

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

2012-08-29 Thread Peter Langfelder
On Wed, Aug 29, 2012 at 3:36 PM, Peter Langfelder peter.langfel...@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

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

2012-08-29 Thread Eloi Mercier
On 12-08-29 04:00 PM, Peter Langfelder wrote: On Wed, Aug 29, 2012 at 3:36 PM, Peter Langfelder peter.langfel...@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

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

2012-08-29 Thread William Dunlap
deparse(substitute(fnc)) will get you part way there. myFunc - function(x) x + 1 applyFunc - function(fnc, x) { cat(fnc is, deparse(substitute(fnc)), \n) fnc - match.fun(fnc) fnc(x) } applyFunc(myFunc, 1:3) fnc is myFunc [1] 2 3 4 applyFunc(function(x)x*10, 1:3) fnc is function(x)

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

2012-08-29 Thread Peter Langfelder
On Wed, Aug 29, 2012 at 4:14 PM, William Dunlap wdun...@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

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

2012-08-29 Thread Rolf Turner
On 30/08/12 10:36, Peter Langfelder 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)