[R] Throwing expressions around

Uwe Ligges ligges at statistik.uni-dortmund.de
Fri Sep 24 18:00:19 CEST 2004


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)


You can try

  fc <- function(m) do.call("curve", list(substitute(m)))
  fc(x^2)


Uwe Ligges



>  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