So if i data.table has more elements than x in a factor column used in join AND x data.table has a list column in .SD it will result an error. When factor in i does not have more elements OR x does not have a list column, issue will not occur:
library(data.table)
dt = data.table(a=factor(1:5, levels=1:10), b=as.list(letters[1:5]))
dt2 = data.table(a=as.factor(1:10))
dt[dt2, .SD, by=.EACHI, on="a", .SDcols="b"]
#Error in `[.data.table`(dt, dt2, .SD, by = .EACHI, on = "a", .SDcols = "b") :
# Logical error. Type of column should have been checked by now
dt2 = data.table(a=as.factor(1:5))
dt[dt2, .SD, by=.EACHI, on="a", .SDcols="b"]
# OK
dt = data.table(a=factor(1:5, levels=1:10), b=letters[1:5])
dt2 = data.table(a=as.factor(1:10))
dt[dt2, .SD, by=.EACHI, on="a", .SDcols="b"]
# OK
R version 3.4.1 (2017-06-30)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.3 LTS
Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.6.0
LAPACK: /usr/lib/lapack/liblapack.so.3.6.0
locale:
[1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_GB.UTF-8 LC_COLLATE=en_GB.UTF-8
[5] LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8
[7] LC_PAPER=en_GB.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] data.table_1.10.5
loaded via a namespace (and not attached):
[1] compiler_3.4.1
So if
idata.table has more elements thanxin a factor column used in join ANDxdata.table has a list column in.SDit will result an error. When factor inidoes not have more elements ORxdoes not have a list column, issue will not occur: