1

I am happily using the data.table package in R for passing large objects by reference. However, the following does not work:

addNewColumn = function(dataTable) {
  dataTable[, newCol:=1]
  return(0)

}
x = data.table(
  id = c(11,22,33),
  data=c(99,99,99)
)
file.remove("x.Rdata")
saveRDS(x, file="x.Rdata")
y = readRDS("x.Rdata")
print(class(y))
res = addNewColumn(y)

although class(y) gives data.table (and data.frame). I.e. it seems that not all the class information is stored on disk and/or recovered from disk...

I am not sure whether I use the latest versions of R and the data.table package but I installed them just a few days ago...

I also discovered that using y = data.table(readRDS("x.Rdata")) instead of y = readRDS("x.Rdata") makes it work again but this statement seems to be senseless since I am casting something to a data.table that already is a data.table.

Best, and thanks for this nice package!!

FW

Fabian Werner
  • 957
  • 11
  • 19
  • Thanks. Most likely a duplicate of [this Q](http://stackoverflow.com/q/28078640/559784). Easiest fix is `y <- alloc.col(readRDS(...))` or `y <- setDT(readRDS(...))`. – Arun Apr 13 '15 at 20:34
  • FAQ in recent data.table version already covers that question. – jangorecki Apr 13 '16 at 01:29

0 Answers0