[datatable-help] Can crash R with a data.table query

Harish harishv_99 at yahoo.com
Thu Jul 1 07:34:19 CEST 2010


Hi,

I am crashing R with the following code (and it might have something to do with data tables as well):

=========


DT <- structure(list(A = c(25L, 85L, 25L, 25L, 85L), B = structure(c(1L, 
1L, 2L, 3L, 3L), .Label = c("a", "b", "c"), class = "factor"), 
    C = c(2L, 65L, 9L, 82L, 823L)), .Names = c("A", "B", "C"), class = c("data.table", 
"data.frame"), row.names = c(NA, -5L))

DT[ , data.table( A, C )[ A==25, C ] + data.table( A, C )[ A==85, C ], by=B ]

=========

For every B, I am trying to sum the C's where A is 25 and 85.

The crash has something to do with my row selection criteria.  First, note that for B=="b", I don't have A==85.  It looks like a numeric(0) is being returned in this case.

In order to avoid the crash, I had to do something like:
   if ( ! identical( DT[ blah ], numeric( 0 ) )

It isn't just that R is unable to handle operations on numeric(0) because I don't get a crash when I just type in "numeric(0) + 2".  So, my guess is that it has something to do with data.table as well.


Harish



      


More information about the datatable-help mailing list