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

Thaden, John J ThadenJohnJ at uams.edu
Thu Jul 6 19:29:42 CEST 2006


Martin Maechler replied to my query "Warning while subsetting...":

MartinM> >>>>> "JohnT" == Thaden, John J <ThadenJohnJ at uams.edu>
MartinM> >>>>>     on Thu, 6 Jul 2006 00:02:10 -0500 writes:

    JohnT> ...
    JohnT> > # While subsetting x, I was surprised to get this warning: 
    JohnT> > y<-x[1:300,]
    JohnT> Warning message:
    JohnT> number of items to replace is not a multiple of replacement
length

  MartinM> and later

    JohnT> Sorry, I omitted background information:
    JohnT> R version: 2.3.0
    JohnT> OS: Windows XP
    JohnT> CPU:  Pentium III, 
    JohnT> RAM:  768 MB

  MartinM> You omitted the most pertinent information: The 
  MartinM> version of 'Matrix' you are using.
  MartinM> The latest released version of Matrix does
  MartinM> *not* show the behavior you mentioned. {So I have 
  MartinM> now spent 20 minutes just because you did not 
  MartinM> update 'Matrix'..}

The Matrix package was version 0.995-10, now is 0.995-11. 
The R base was version 2.3.0, now is 2.3.1. 
Subsetting 'y <- x[1:300,]' now works. Please accept my apology.

    JohnT> Also, what command-line memory settings might prevent
    JohnT> R from crashing while using the Matrix package to 
    JohnT> convert my 600 X 4482 dgTMatrix to the dgCMatrix class
    JohnT> or to an expanded Matrix, via the as() function? I can
    JohnT> do this with half of the matrix, 300 x 4482.

  MartinM> It's hard to believe that you get a "crash" 
  MartinM> when coercing to 'dgC' -- but of course this 
  MartinM> really depends how much memory you have already
  MartinM> goggled up by other large objects in your R
  MartinM> workspace, or by other applications running at
  MartinM> the same time in Windows.  Coercing to a full 
  MartinM> matrix will of course require 8 * 601 * 4482 = 
  MartinM> 21549456 extra bytes just for the numbers.
  MartinM> That's only 21.5 Megabytes, so I wonder..
  MartinM>
  MartinM> I have never seen R crashes from using 'Matrix', 
  MartinM> but then I work with an operating system, not 
  MartinM> with M$ Windows. 
  MartinM>
  MartinM> Maybe you meant you got an error message 
  MartinM> "... memory allocation .."?

Testing again, I closed all applications; disabled antivirus; 
opened RGui; removed all R objects but 'x' (a 600x4482 dgTMatrix); 
opened WinXP's 'Task Manager'; saw only "Rgui" under 
'Applications'; saw processes using a total of 287 MB of memory
under 'Processes'; closed 'Task Manager'; and typed R commands:

> # Steps leading to an R crash...
> ls()
[1] "x"
> str(x)
Formal class 'dgTMatrix' [package "Matrix"] with 6 slots
  ..@ i       : int [1:923636] 1 2 3 4 5 6 7 8 9 10 ...
  ..@ j       : int [1:923636] 1 1 1 1 1 1 1 1 1 1 ...
  ..@ Dim     : int [1:2] 600 4482
  ..@ Dimnames:List of 2
  .. ..$ : chr [1:601] "50" "51" "52" "53" ...
  .. ..$ : chr [1:4482] "1" "2" "3" "4" ...
  ..@ x       : num [1:923636] 50.2 51.2 52.2 53.2 54.2 ...
  ..@ factors : list()
> gc()
          used (Mb) gc trigger (Mb) max used (Mb)
Ncells  183529  5.0     407500 10.9   350000  9.4
Vcells 1928101 14.8    2286173 17.5  1928652 14.8
> library(Matrix)
Loading required package: lattice
> gc()
          used (Mb) gc trigger (Mb) max used (Mb)
Ncells  627772 16.8    1073225 28.7  1073225 28.7
Vcells 2165773 16.6    3345184 25.6  2332013 17.8
> search()
 [1] ".GlobalEnv" "package:Matrix" "package:lattice"
 [4] "package:methods" "package:stats" "package:graphics"  
 [7] "package:grDevices" "package:utils" "package:datasets"
 [10] "Autoloads"  "package:base"     
> #Now the line that causes crashes...
> y <- as(x,"dgCMatrix")

After ~10 seconds, R blinks off and a WinXP dialog appears: 

  R for Windows GUI front-end has encountered 
  a problem and needs to close.  We are sorry
  for the inconvenience....Error signature:
  AppName: rgui.exe  AppVer: 2.31.38247.0  
  ModName: matrix.dll Offset: 0000ff31....
  Report error?

Sincerely,
John Thaden

Confidentiality Notice: This e-mail message, including any a...{{dropped}}



More information about the R-help mailing list