Looking for a way to use the replacement for quoted language objects as an expression.
substituteexpects to get a lazy expression in expr.
The goal is to replace .exprwith expr.template, which is a language object created dynamically based on metadata.
expr = quote(x <- f(10))
expr.template = quote(g(.expr, flag = TRUE))
quote(g(x <- f(10), flag = TRUE))
h = function(expr, expr.template){
eval(substitute(
substitute(
.expr.template,
list(.expr = expr)
),
list(.expr.template = expr.template)
))
}
h(expr = expr, expr.template = expr.template)
Therefore, I would be surprised if there was no more canonical way to handle this. A solution of base R is preferred.
source
share