Re: [R] help with as.function

2004-07-13 Thread Gabor Grothendieck
  unsl.edu.ar> writes:

> 
> HI, sorry but i don't understand how to make a function with as.function()
> 
> formula<-"2+3*x"
>  formu<-as.symbol(formula)
> > formu
> 2+3*x
>  formul<-as.function(alist(x=,formu))
> curve(formul,1,5,col="blue")
> Error in xy.coords(x, y, xlabel, ylabel, log) :
> x and y lengths differ
> > typeof(formul)
> [1] "closure"
> 
> and not plot the curve function, Why? Thanks Ruben

Here are two ways to create a function out of strings although
neither uses as.function:

f <- function(x){}
body(f) <- parse(text="2+3*x")

f <- eval(parse(text=paste("function(x)","2+3*x")))

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] help with as.function

2004-07-13 Thread Sundar Dorai-Raj

[EMAIL PROTECTED] wrote:
HI, sorry but i don't understand how to make a function with as.function()
formula<-"2+3*x"
 formu<-as.symbol(formula)
formu
2+3*x
 formul<-as.function(alist(x=,formu))
curve(formul,1,5,col="blue")
Error in xy.coords(x, y, xlabel, ylabel, log) :
x and y lengths differ
typeof(formul)
[1] "closure"
and not plot the curve function, Why? Thanks Ruben
Hi Ruben,
How about this?
ftext <- "2 + 3 * x"
f <- as.function(alist(x=, eval(parse(text = ftext
or as a one-liner:
f <- as.function(alist(x=, eval(parse(text = "2 + 3 * x"
--sundar
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] help with as.function

2004-07-13 Thread solares
HI, sorry but i don't understand how to make a function with as.function()

formula<-"2+3*x"
 formu<-as.symbol(formula)
> formu
2+3*x
 formul<-as.function(alist(x=,formu))
curve(formul,1,5,col="blue")
Error in xy.coords(x, y, xlabel, ylabel, log) :
x and y lengths differ
> typeof(formul)
[1] "closure"

and not plot the curve function, Why? Thanks Ruben

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html