I have a function f:
f=function(){}
and a variable
var=f
I would like to know how to get the name of the fun
When you do: var=f
you are actually creating a new variable var
with the same content as f
.
In summary, you can not access the name of f
in the example you gave since R is not keeping any history of this.
I am not sure what you want to do exactly, but the following might be helpful:
#definition of the function f
f=function(){}
#assignation of the reference 'f' instead of the content of f with substitute()
var=substitute(f)
#checking what is inside var
var
> f
#if you need to use f through var, you have to use eval()
eval(var)
> function(){}
var=f
assignes function(){}
to var
. It only knows that it is a function and 'forgets' about variable name. This code:
f <- function(){}
var <- f
has the same effect as this:
var <- function(){}