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

From: Henrique Dallazuanna <wwwhsd_at_gmail.com>
Date: Mon, 10 Dec 2007 13:34:29 -0200

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.
Received on Mon 10 Dec 2007 - 15:41:54 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 Tue 11 Dec 2007 - 08: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.