[datatable-help] Error on := causes data.table to be left in a bad state

Chris Neff caneff at gmail.com
Fri Dec 16 15:47:12 CET 2011


99% positive this is a bug but I like to get confirmation before
making reports.  Still on 2.12.1 64-bit R on Linux, latest SVN version
of data.table with debugging turned on.

If you do

DT <- data.table(x=1:10)

DT[, a := letters]


You will get the error:

Error in `[.data.table`(DT, , `:=`(a, letters)) :
  Tried to assign 26 items to target of 100 (can recycle but must be
exact multiple). If users ask us to change this to a warning, we will
change it; please ask maintainer('data.table').


Which is fine.  However, the state of DT after that is that DT has two
columns, x (the column it started with) and a, a column full of NULL
values. If I then try to do something like

DT[, a:=5]

It will say the following error:

Error in `[.data.table`(DT, , `:=`(a, 5)) :
  cannot coerce type 'double' to vector of type 'NULL'


Finally, if I make DT bigger, and try the same thing:

DT <- data.table(x=1:1e6)
DT[, a := letters]

It will give me the same error message, but now the state of DT is
even more screwed up. If I try to just print DT I get:

> DT
Error in names(ans) = names(x) :
  'names' attribute [2] must be the same length as the vector [1]


More information about the datatable-help mailing list