[R] How to read in expressions as function parameters?

From: Alex Wang <alecwang80_at_gmail.com>
Date: Sun, 9 Dec 2007 16:45:36 -0600


Hi:

   There, I've got a question about how to read in expressions as function parameters and it really bothered me.

 I'm going to use curve() function to plot curves, and I'd like to write a menu function to let use input math expressions.

  say, if I'd like curve(3*x*x-4/x, 10, 100), I use scan() to read in the math expression

form<- scan(file = "", what = character(0), n=1,strip.white = TRUE,quiet=TRUE )
then get form as a string. "3*x*x-4/x"
Use parse() to convert it into expression form2<-parse(text=form)
then form2=expression(3*x*x-4/x).

However, curve(form2,10,100) doesn't work at all.

Is there anyway to get this done?

Thanks a lot!

Alex

        [[alternative HTML version deleted]]



R-help_at_r-project.org 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. Received on Sun 09 Dec 2007 - 22:54:42 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 10 Dec 2007 - 16:30:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.