[R] How Can I Execute a String Expression?
bgunter.4567 at gmail.com
Tue Jun 13 04:30:39 CEST 2017
eval(parse(text = yourstring)) # your string must be quoted, because
that's what a string is.
But .... don't do this! (usually)
install.packages("fortunes") ## if not already downloaded and installed
See ?substitute and ?bquote for perhaps better ways to proceed.
"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Mon, Jun 12, 2017 at 6:55 PM, Donald Macnaughton <donmac at matstat.com> wrote:
> I have the string ggstr that I've built with string manipulation:
> ggstr = "ggplot(df1, aes(x,y)) + geom_smooth(se=FALSE, span=0.01)"
> Assuming df1 is properly defined, this string will execute properly if I
> submit it manually without the quotes. How can execute the command as a
> string, so that I can run it repeatedly (with minor modifications) in a
> loop? Presumably, it would be something like:
> Thanks for your help,
> Don Macnaughton
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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