[R] Throwing expressions around
Roger D. Peng
rpeng at jhsph.edu
Fri Sep 24 17:42:45 CEST 2004
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
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
More information about the R-help
mailing list