[R] Throwing expressions around

Barry Rowlingson B.Rowlingson at lancaster.ac.uk
Fri Sep 24 17:35:51 CEST 2004


I'm trying to write some code that throws a few expressions around the
place, and I've boiled down the problem to be equivalent to this.

Consider the curve function which plots expressions in 'x':

  > curve(x^2)

Now wrap that in the most naive wrapper function:

  > fc=function(m){curve(m)}

  and try it:

  > fc(x^2)
  Error in eval(expr, envir, enclos) : Object "x" not found

What could be done to my 'fc' or the expression processing of curve to
make this sort of thing work?

What I also want to do is provide a default, something like:

  fc = function(m=sqrt(x)){curve(m)}

It's not actually curve() that I want to call, but something similar 
I've written myself, so I can fiddle with that as I wish.

I've had a read of the R Language Definition - I imagine the answer is 
in there somewhere...

Barry




More information about the R-help mailing list