An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-help/attachments/20071209/d53a4c13/attachment.pl
How to read in expressions as function parameters?
3 messages · Alex Wang, Henrique Dallazuanna, Alexwang
Try this:
form<- scan(file = "", what = character(0), n=1,strip.white =
TRUE,quiet=TRUE )
form2<-parse(text=form)
foo <- function(x){}
body(foo) <- form2
curve(foo,10,100)
On 09/12/2007, Alex Wang <alecwang80 at gmail.com> wrote:
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.
Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
Thanks a lot!
Henrique Dallazuanna wrote:
Try this:
form<- scan(file = "", what = character(0), n=1,strip.white =
TRUE,quiet=TRUE )
form2<-parse(text=form)
foo <- function(x){}
body(foo) <- form2
curve(foo,10,100)
On 09/12/2007, Alex Wang <alecwang80 at gmail.com> wrote:
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.
-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
______________________________________________ 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.
View this message in context: http://www.nabble.com/How-to-read-in-expressions-as-function-parameters--tp14244375p14268331.html Sent from the R help mailing list archive at Nabble.com.