Peter: Yes, this is a bug. The line
if ([EMAIL PROTECTED] <= nrow(x)) should actually read if (([EMAIL PROTECTED] <= length([EMAIL PROTECTED])) && ([EMAIL PROTECTED] < [EMAIL PROTECTED] + 1])) --> fixed upstream. Thanks David -------- Hello, The write.matrix.csr() function of the e1071 package contains a bug. Try the following: library(e1071) m <- 1 - diag(10) sm <- as.matrix.csr(m) write.matrix.csr(sm) The resulting file (out.dat) contains only the two lines below: 2:1 3:1 4:1 5:1 6:1 7:1 8:1 9:1 10:1 1:1 3:1 4:1 5:1 6:1 7:1 8:1 9:1 10:1 This is obviously wrong as the matrix m has 90 non-zero entries. The function is implemented as write.matrix.csr <- function (x, file="out.dat", y=NULL) { on.exit(sink()) if(!require("methods")) stop("Could not load package 'methods'.") if (!is.null(y) & (length(y) != nrow(x))) stop(paste("Length of y (=", length(y), ") does not match number of rows of x (=", nrow(x), ")!", sep="")) sink(file) for (i in 1:nrow(x)) { if (!is.null(y)) cat (y[i],"") if ([EMAIL PROTECTED] <= nrow(x)) for (j in [EMAIL PROTECTED]:([EMAIL PROTECTED] - 1)) cat([EMAIL PROTECTED], ":", [EMAIL PROTECTED], " ", sep="") cat("\n") } } The bug is caused by the line if ([EMAIL PROTECTED] <= nrow(x)) that is completely meaningless. In the above example nrow(x) is 10 and [EMAIL PROTECTED] is the vector 1 10 19 28 37 46 55 64 73 82 91 Entries of [EMAIL PROTECTED] has nothing to do with the number of rows in the matrix. To fix the bug this line must be removed. Best regards, ______________________________________________ R-help@r-project.org 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.