[R] SUMMARY: R crash with ''library(Matrix); as(x, "dgCMatrix")' [was: Warning while subsetting...]

From: Thaden, John J <ThadenJohnJ_at_uams.edu>
Date: Sun 09 Jul 2006 - 04:52:56 EST

With thanks to Matrix package co-author Martin Maechler, I'm happy to report satisfactory closure of two recent threads I initiated about that package:

In the first, I reported seeing a warning message after selecting a subset of a matrix 'M' of class "dgTMatrix" via the first but not the second of these commands:  

  M10 <- M[1:10,]
  M10 <- M[1:10,1:10]

Acting on Martin's advice, I upgraded Matrix version 0.995-10 to version 0.995-11. This eliminated the warning message.

In the second, I reported that class-conversion of a self-constructed "dgTMatrix" of dimension 600 X 4482 caused R to crash when done via either of the first two but neither of the last two of these commands:

  Mc <- as(M, "dgCMatrix")
  Mm <- as(M, "matrix")
  Mc <- rbind(as(M[1:300,], "dgCMatrix"), as(M[301:600], "dgCMatrix")
  Mm <- rbind(as(M[1:300,], "matrix"), as(M[301:600], "matrix")

I surmised this was a memory issue but Martin pointed out the memory demand to hold even the expanded sparse matrix is actually rather small (8 x 600 x 4482 = 21549456 bytes = 21.5 Megabytes).  

For obvious bandwidth reasons, I did not post my large matrix, so Martin created one of his own. Neither he nor I could reproduce crashes with his matrix. Offlist, I sent him my matrix. Upon class-conversion, it crashed his machine too.

Upon inspection, Martin discovered that my matrix did not conform to the dgTMatrix class as defined in Matrix. In particular, my slots M@i and M@j were integer vectors beginning with ones, i.e., they respectively indexed the first row and column of the matrix as "1", not as "0".

However, correcting this did not stop crashes, until I also realized that M@i had 601 (not 600) unique integer values, and corrected my Dims slot (M@Dims) to be c(601,4482). This stopped the crashes.

Once created, Matrix objects behave like matrix objects in the sense that "one-based" indexing is used to subset them or re-assign values to them. But for users who create them, especially using the new() function, it is helpful to remind oneself that Matrix objects are created and stored using "zero-based" indexing. This fact is mentioned only obliquely in the current version's PDF file and R-accessible documentation. Hopefully that will change.

Again, my thanks to Martin. For me this experience confirms The vigor of open-source, forum-supported projects.

-John Thaden, Ph.D.
Research Assistant Professor of Geriatrics University of Arkansas for Medical Sciences Little Rock, AR 72205
USA Confidentiality Notice: This e-mail message, including any a...{{dropped}}

R-help@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 Received on Sun Jul 09 04:56:29 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 09 Jul 2006 - 06:16:27 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.