Thomas Lumley <[EMAIL PROTECTED]> writes:

> On Wed, 30 Jul 2003, Damon Wischik wrote:
> 
> >
> > Why does
> > > curve(function(y) y^2, from=0,to=1)
> > not work, whereas
> > > myf <- function(y) y^2
> > > curve(myf, from=0,to=1)
> > work?
> >
> 
> Because someone was trying to be too clever in writing curve().  The first
> argument must either be an expression with the free variable `x' or the
> *name* of a function. You can't specify a literal function or the name of
> an expression.
> 
> The reason is that it is hard to tell whether an argument is a function or
> an expression without evaluating it, and if it's an expression you may not
> be able to evaluate it.
> 
> You could always use
>   plot(function(y) y^2)

Actually, it wouldn't be too hard to use identical(sexpr[[1]],
as.name("function")) and detect an explicit function definition, so
someone could have been even more clever...

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - ([EMAIL PROTECTED])             FAX: (+45) 35327907

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

Reply via email to