packageVersion("data.table")
# [1] ‘1.17.99’
x = data.table(a=1:3)
ncol = truelength(x)
ncol
# [1] 1025
f = function(DT) {
for (i in seq_len(ncol + 100L)) {
DT[,paste0("new",i):=1:3]
}
}
f(x) # I thought there was a warning here that := on i==ncol did a realloc
dim(x)
# [1] 3 1025 # wrong result
f = function(DT) {
DT[, paste0("new", seq_len(ncol + 100L)) := 1:3]
NULL
}
f(x)
dim(x)
# [1] 3 1025 # wrong result
f = function(DT) {
for (i in seq_len(ncol + 100L)) {
DT[,paste0("new",i):=1:3]
}
DT # needed in this case
}
x = f(x) # x= needed in this case
dim(x)
# [1] 3 1126 # correct result
x = data.table(a = 1:3)
f = function(DT) {
for (j in seq_len(ncol + 100L)) set(DT, NULL, paste0("new", j), 1:3)
}
f(x)
# Error in set(DT, NULL, paste0("new", j), 1:3) :
# Internal error in assign: input dt has not been allocated enough column slots. l=1025, tl=1025, adding 1. Please report to the data.table issues tracker.
# dim(x)
I seem to remember there was a warning. Maybe it isn't happening in this case for some reason. Need to reinstate the warning and add a test for it.
I seem to remember there was a warning. Maybe it isn't happening in this case for some reason. Need to reinstate the warning and add a test for it.