[Rd] scoping error in xy.coords (PR#932)

kjetilh@umsanet.edu.bo kjetilh@umsanet.edu.bo
Fri, 4 May 2001 17:22:32 +0200 (MET DST)


Hola!

> rm(list=ls(all=TRUE))

> x <- 1:20
> y <- 1+x+rnorm(x)

> xy.coords(y  ~ x,NULL)

... expected output, correct, but when called from inside lowess:

>   lowess(y ~ x)
Error in xy.coords(x, y) : x and y lengths differ
> debug(xy.coords)
>   lowess(y ~ x)
debugging in: xy.coords(x, y)

... long listing deleted

    if (is.language(x)) {
        if (inherits(x, "formula") && length(x) == 3) {
            ylab <- deparse(x[[2]])
            xlab <- deparse(x[[3]])
            y <- eval(x[[2]], parent.frame())
            x <- eval(x[[3]], parent.frame())
        }
        else stop("invalid first argument")
    }
    else
... deleted
debug: if (inherits(x, "formula") && length(x) == 3) {
    ylab <- deparse(x[[2]])
    xlab <- deparse(x[[3]])
    y <- eval(x[[2]], parent.frame())
    x <- eval(x[[3]], parent.frame())
} else stop("invalid first argument")
Browse[1]> n
debug: ylab <- deparse(x[[2]])
Browse[1]> n
debug: xlab <- deparse(x[[3]])
Browse[1]> n
debug: y <- eval(x[[2]], parent.frame())
Browse[1]> n
debug: x <- eval(x[[3]], parent.frame())
Browse[1]> n
debug: if (length(x) != length(y)) {
    if (recycle) {
        if ((nx <- length(x)) < (ny <- length(y))) 
            x <- rep(x, length = ny)
        else y <- rep(y, length = nx)
    }
    else stop("x and y lengths differ")
}
Browse[1]> x
y ~ x
Browse[1]> y
NULL

x and y have their original values from the call, the evaluation 
inside is.formula .... have failed.

Browse[1]> c
Error in xy.coords(x, y) : x and y lengths differ



Kjetil Halvorsen

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._