[R] Question about curve function

Uwe Ligges ligges at statistik.tu-dortmund.de
Tue Jun 7 16:17:44 CEST 2011



On 07.06.2011 11:57, peter dalgaard wrote:
>
> On Jun 6, 2011, at 11:22 , Prof Brian Ripley wrote:
>
>> As a further example of the trickiness, the "function" method of plot() relies on curve(x, ...) being a request to plot the function x(x) against x.  I've added a comment to that effect to the help page.
>
> Ouch. This springs to mind:
>
>> fortune(106)
>
> If the answer is parse() you should usually rethink the question.
>     -- Thomas Lumley
>        R-help (February 2005)
>
>
> but curve() predates that insight by half a decade or more. It could probably do with a redesign, if anyone is up to it.
>
> By the way, it really does work if the 2nd arg is an expression object (as opposed to an expression evaluating to an expression object):
>
> do.call(curve,list(expression(x)))
>
> or
>
> cl<- quote(curve(x))
> cl[[2]]<- expression(x)
> eval(cl)
>
> (The trouble with nonstandard evaluation is that it doesn't follow standard evaluation rules...)

If this is not already a fortune, I will add it.

Which is why I useually circvumvent curve(). It is typically faster to 
just evaluate a function at positions x and plot it rather than thinking 
minutes about how curve() expects its arguments.

Uwe



More information about the R-help mailing list