I think you want some eval/substitute action, such as

fc <- function(m) { eval(substitute(curve(m))) }

-roger

Barry Rowlingson wrote:
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

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



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

Reply via email to