[R] converting character string to an expression
Stephen Tucker
brown_emu at yahoo.com
Wed Aug 8 23:54:26 CEST 2007
I think you're looking for
parse(text=paste(letters[1:3], collapse="+"))
--- Jarrod Hadfield <j.hadfield at shef.ac.uk> wrote:
> 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
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list