I have encountered a snippet of code where call contains another call. For example:
a <- 1
b <- 2
# First call
foo <- quote(a + a)
# Second call (call c
I found a CRAN package that can do this - oshka: Recursive Quoted Language Expansion.
It recursively replaces quoted language calls by objects in environment.
a <- 1
b <- 2
foo <- quote(a + a)
bar <- quote(foo ^ b)
So call oshka::expand(bar)
gives (a + a)^b
and eval(oshka::expand(bar))
returns 4
.
It also works with more complicated calls that @Oliver suggested:
d <- 3
zz <- quote(bar + d)
oshka::expand(zz)
# (a + a)^b + d