[R] Bug with curve?

Martin Maechler maechler at stat.math.ethz.ch
Fri Feb 1 15:46:31 CET 2008


>>>>> "BB" == Ben Bolker <bolker at ufl.edu>
>>>>>     on Fri, 1 Feb 2008 14:03:15 +0000 (UTC) writes:

    BB> Paul Smith <phhs80 <at> gmail.com> writes:
    >> 
    >> Dear All,
    >> 
    >> Take this code:
    >> 
    >> > f <- function(x) exp(-x)*x-0.05
    >> > g <- function(x) 0
    >> > curve(f,0,5)
    >> > curve(g,add=T)
    >> Error in xy.coords(x, y) : 'x' and 'y' lengths differ
    >> >
    >> 
    >> However, with
    >> 
    >> g <- function(x) x-x
    >> 
    >> no error is generated.
    >> 
    >> 

    BB> The first paragraph of "details" in the help page 
    BB> says:

    BB> . 'x(t)' or 'expr' (with 'x' inside) must return a numeric of the same
    BB> length as the argument 't' or 'x'.

yes, thanks Ben.

    BB> So no, technically this is not a bug.

why only "technically"?

Paul wouldn't also be able to integrate(g, .), just
the error message would be slightly more helpful :

  Error in integrate(g, 0, 1) : 
    evaluation of function gave a result of wrong length



    BB> The R idiom for adding a horizontal line to the plot is
    BB> abline(h=...) 

    BB> cheers
    BB> Ben Bolker



More information about the R-help mailing list