[R] converting character string to an expression

Jarrod Hadfield j.hadfield at shef.ac.uk
Wed Aug 8 20:42:16 CEST 2007


Hi Everyone,

I would simply like to coerce a character string into an expression:  
something like:

as.expression(paste(letters[1:3], collapse="+"))

but I can't seem to get rid of the quotes.  The only way I can get it  
to work is using as.formula:

as.expression(as.formula(paste("~", paste(letters[1:3], collapse="+"))))

but this requires the expression to have a tilde, which it will not  
always have.

Thanks,

Jarrod



More information about the R-help mailing list