Skip to content
Prev 76033 / 398502 Next

Substituted arguments surviving multiple function calls

Michael Hoffman wrote:
Hi, Michael,

How about the following:

d <- data.frame(a1 = c(4, 2), a2 = c(6, 7))

f1 <- function(x, d) {
   eval(substitute(x), d)
}

f2 <- function(x, d) {
   eval(substitute(f1(x, d)), list(x = substitute(x), d = d))
}

f1(a1, d)
f2(a1, d)

Note that I redefined "f1" to do away with the "do.call". Also, it's 
always safest to pass "d" as an argument rather than rely on it being in 
  .GlobalEnv.

There may be others who suggest a different approach.

HTH,

--sundar