[R] help in substitute function

Alberto Monteiro albmont at centroin.com.br
Fri Oct 5 20:39:32 CEST 2007


Ronaldo Reis Junior asked:
> 
> I try to use a substitute function to generalise a equation.
> 
> I have this:
> 
> expression(1+2*pred+3*lat)
> 
> (...) My expected result is:
> 
> expression(1 + 2 * x1 + 3 * x2)
> 
Check message by Thomas Lumley on 2007-03-27 (command...
RSiteSearch("Replacement in an expression - can't use parse()")
... will get it among others)

Quoting and adapting:

e <- expression(1+2*pred+3*lat)
do.call("substitute", list(e[[1]], list(pred=quote(x1),lat=quote(x2))))
# 1 + 2 * x1 + 3 * x2

(parece mágica, não é?)

Alberto Monteiro



More information about the R-help mailing list