[R] equation on the object

Thomas Lumley tlumley at u.washington.edu
Thu Dec 12 20:32:03 CET 2002


On Thu, 12 Dec 2002, Ronaldo Reis Jr. wrote:

> Hi,
>
> I try to put an equation on a object to use in curve for example,
> but it don't work, it possible to make a object of an equation?
>
> ex.
>
> fx <- a + b*x
> for(a in 0){for(b in 1){curve(fx,...)}}
>

It's tricky because curve allows both expressions and functions as
arguments.

Your example couldn't work because
   fx <- a + b*x
sets fx to a number (or vector), the number a+b*x.  You would want
   fx <- expression(a+b*x)
or
   fx <- quote(a+b*x)
to store the expression "a+b*x"

Now, could reasonably be expected to work, but doesn't.  It doesn't
because curve assumes that its argument is a literal expression involving
x or a function. So you need to do either

 for(a in 0){for(b in 1){curve(a+b*x)}}
or
 fx<- function(x) a+b*x
 for(a in 0){for(b in 1){curve(fx)}}


	-thomas




More information about the R-help mailing list