[R] Question about error message - or is it a bug?

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Fri Nov 10 18:01:29 CET 2006


Carmen Meier said the following on 11/10/2006 9:46 AM:
> Hi to all ... the same code, but another question.
> 
> I changed only the type='n' to type='l' and debugged the function xy.coords.
> with type = 'l' :
> there are the correct values of x and y inside the function xy.coords
> but the y value is filled with NA seems that the length is matching now 
> because of the NAs
> 
> with type = 'n' :
> there are the wrong values of x in the function xy.coords
> and the y value is not filled with NA
> So there is a length mismatch additionally to the wrong x values
> 
> Maybe anybody could evaluate whether this is an error (some kind of 
> misunderstanding)  from me or a bug
> 
> Regards Carmen
> see codes below


Hi, Carmen
The problem is not in xy.coords, but in chron:::plot.times. Why do you 
set y to c(0, 10)? This is not the same length as x which is why you are 
getting this error. Since it's not clear what type of plot you expect, 
it's difficult to comment further. Try:

debug(chron:::plot.times)

to see how your function call is being interpreted by the code. Also, in 
the future, please tell us where to find non-base functions such as "times".

Thanks,

--sundar


> 
> #------------------- Code -------------------------------------------
> 
> 
> time <- 
> c("2:25:00","2:26:00","2:27:00","2:28:00","2:29:00","2:30:00","2:31:00",
>      "2:32:00","2:33:00","2:34:00","2:35:00","2:36:00","2:37:00","2:38:00",
>  
> "2:39:00","2:40:00","2:41:00","2:42:00","2:43:00","2:44:00","2:45:00",
>  
> "2:46:00","2:47:00","2:48:00","2:49:00","2:50:00","2:51:00","2:52:00",
>  
> "2:53:00","2:54:00","2:55:00","2:56:00","2:57:00","2:58:00","2:59:00",
>  
> "3:00:00","3:01:00","3:02:00","3:03:00","3:04:00","3:05:00","3:06:00",
>  
> "3:07:00","3:08:00","3:09:00","3:10:00","3:11:00","3:12:00","3:13:00",
>           "3:14:00")
> y <- c(0,10)
> plot(times(time), y, type='n')
> 
> 
> #------------------ Debugging ---------------------------------------
> debug(xy.coords)
> plot(times(time), y, type='l')
> 
> 
> debug: if (is.null(y)) {
>      ylab <- xlab
>      if (is.language(x)) {
>          if (inherits(x, "formula") && length(x) == 3) {
>              ylab <- deparse(x[[2]])
>              xlab <- deparse(x[[3]])
>              y <- eval(x[[2]], environment(x), parent.frame())
>              x <- eval(x[[3]], environment(x), parent.frame())
>          }
>          else stop("invalid first argument")
>      }
>      else if (inherits(x, "ts")) {
>          y <- if (is.matrix(x))
>              x[, 1]
>          else x
>          x <- stats::time(x)
>          xlab <- "Time"
>      }
>      else if (is.complex(x)) {
>          y <- Im(x)
>          x <- Re(x)
>          xlab <- paste("Re(", ylab, ")", sep = "")
>          ylab <- paste("Im(", ylab, ")", sep = "")
>      }
>      else if (is.matrix(x) || is.data.frame(x)) {
>          x <- data.matrix(x)
>          if (ncol(x) == 1) {
>              xlab <- "Index"
>              y <- x[, 1]
>              x <- seq_along(y)
>          }
>          else {
>              colnames <- dimnames(x)[[2]]
>              if (is.null(colnames)) {
>                  xlab <- paste(ylab, "[,1]", sep = "")
>                  ylab <- paste(ylab, "[,2]", sep = "")
>              }
>              else {
>                  xlab <- colnames[1]
>                  ylab <- colnames[2]
>              }
>              y <- x[, 2]
>              x <- x[, 1]
>          }
>      }
>      else if (is.list(x)) {
>          xlab <- paste(ylab, "$x", sep = "")
>          ylab <- paste(ylab, "$y", sep = "")
>          y <- x[["y"]]
>          x <- x[["x"]]
>      }
>      else {
>          if (is.factor(x))
>              x <- as.numeric(x)
>          xlab <- "Index"
>          y <- x
>          x <- seq_along(x)
>      }
> }
> Browse[1]>
> debug: if (inherits(x, "POSIXt")) x <- as.POSIXct(x)
> Browse[1]>
> debug: if (length(x) != length(y)) {
>      if (recycle) {
>          if ((nx <- length(x)) < (ny <- length(y)))
>              x <- rep(x, length.out = ny)
>          else y <- rep(y, length.out = nx)
>      }
>      else stop("'x' and 'y' lengths differ")
> }
> Browse[1]> x
>   [1] 0.1006944 0.1013889 0.1020833 0.1027778 0.1034722 0.1041667 
> 0.1048611 0.1055556 0.1062500
> [10] 0.1069444 0.1076389 0.1083333 0.1090278 0.1097222 0.1104167 
> 0.1111111 0.1118056 0.1125000
> [19] 0.1131944 0.1138889 0.1145833 0.1152778 0.1159722 0.1166667 
> 0.1173611 0.1180556 0.1187500
> [28] 0.1194444 0.1201389 0.1208333 0.1215278 0.1222222 0.1229167 
> 0.1236111 0.1243056 0.1250000
> [37] 0.1256944 0.1263889 0.1270833 0.1277778 0.1284722 0.1291667 
> 0.1298611 0.1305556 0.1312500
> [46] 0.1319444 0.1326389 0.1333333 0.1340278 0.1347222
> attr(,"format")
> [1] "h:m:s"
> Browse[1]> y
>   [1]  0 10 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 
> NA NA NA NA NA NA NA NA
> [31] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
> Browse[1]>
> #----------------------------------------------------------------------
> 
> debug(xy.coords)
> plot(times(time), y, type='n')
> 
> 
> 
> debug: if (length(x) != length(y)) {
>      if (recycle) {
>          if ((nx <- length(x)) < (ny <- length(y)))
>              x <- rep(x, length.out = ny)
>          else y <- rep(y, length.out = nx)
>      }
>      else stop("'x' and 'y' lengths differ")
> }
> Browse[1]>
> debug: if (recycle) {
>      if ((nx <- length(x)) < (ny <- length(y)))
>          x <- rep(x, length.out = ny)
>      else y <- rep(y, length.out = nx)
> } else stop("'x' and 'y' lengths differ")
> Browse[1]>
> Fehler in xy.coords(x, y, xlabel, ylabel, log) :
>          'x' and 'y' lengths differ
>  > x
>   [1] 2 1 0 0 0 1 0 0 0 3 3 3
>  > y
> [1]  0 10
> 
> ______________________________________________
> 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
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list