My question is how to extract the name of a variable from a function that is called in another function in R?
To illustrate, here is an example:
a <- function(variable) {
print(deparse(substitute(variable)))
internala(substitute(variable))
}
internala <- function(variableXX) {
namex=deparse(substitute(variableXX))
print(namex)
}
Calling the function a gives the following result:
>a(whatever)
[1] "whatever"
[1] "substitute(variable)"
which means that i can extract the name of the variable whatever from a, but not from internala.
Any thoughts on this?
Any help will be appreciated!
Maria
You could change
afunction to substitute argument of aninternalafunction andevalit:As hadley suggest its better to directly pass names. I usually do something like that:
Each function could be call without passing name, but you can override it. For example: