Adding new columns to a data.table by-reference within a function not always working
Is this a pointer issue ala this issue, like serializing a data.table destroys the over-allocated pointers?
Yes loading from disk sets the external pointer to NULL. We will have to over-allocate again.
Is there a simple way to restore them?
Yes. You can test for truelength()
of the data.table, and if it's 0
, then use setDT()
or alloc.col()
on it.
truelength(test2) # [1] 0
if (!truelength(test2))
setDT(test2)
truelength(test2) # [1] 100
foobar(test2, "new")
test2[]
# id val new
# 1: a 1 1
# 2: b 2 1
This should probably go in as a FAQ (can't remember seeing it there).
Already in FAQ in Warning Messages section.