Re: [R] help with as.function

From: Sundar Dorai-Raj <sundar.dorai-raj_at_pdf.com>
Date: Wed 14 Jul 2004 - 10:28:40 EST

solares@unsl.edu.ar 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



R-help@stat.math.ethz.ch 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 Received on Wed Jul 14 10:35:40 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:54:56 EST