en <- quoting.env(c('+', '(', 'a', 'b', '*'), environment())
evalq(a+b, en) # a+b
evalq(a+(b*a), en) # a+(b*a)
z <- 100
evalq(a+(b*a)*z, en) #a+(b*a)*100
##We can build a function that does something like substitute() like this:
ersatz.substitute <- function(expr, envir=arg_env(expr)) {
parent <- as.environment(envir)
en <- quoting.env(setdiff(all.names(expr), ls(parent)), parent)
eval(expr, en)
}
ersatz.substitute(quote(a+b+c), list(b=quote(q+y))) # returns a+(q+y)+c
Run the code above in your browser using DataLab