Consider this function a()
, which displays the argument that was passed:
a <- function(x) { message("The input is ", deparse(substitute(x))) } a("foo")
It works. But when a()
is called from another function, it no longer prints the original argument names:
b <- function(y) { a(y) } b("foo")
One solution that seems to work is to port to other substitute
and eval
:
a1 <- function(x) { message("The input is ", deparse(eval(substitute(substitute(x)), parent.frame()))) } a1("foo")
But it seems inelegant. And it fails if I add another layer:
c1 <- function(z) { b1(z) } c1("foo")
Is there a good general way to get the original argument?
source share