Open
Description
When assigning to an element of a list column a
using e.g. dt$a[[1]]
, the column remains a list-column only if the table has more than one row. If the table has one single row, the column is converted to an atomic type.
Minimal reproducible example
library("data.table")
dt <- data.table(a = list(1, 2))
dt$a[[1]] <- 1
is.list(dt$a)
#> [1] TRUE # as expected!
dt <- data.table(a = list(1))
dt$a[[1]] <- 1
is.list(dt$a)
#> [1] FALSE # unlike expected!
Output of sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Fedora 31 (Thirty One)
Matrix products: default
BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so
locale:
[1] LC_CTYPE=en_US.utf8 LC_NUMERIC=C
[3] LC_TIME=en_US.utf8 LC_COLLATE=en_US.utf8
[5] LC_MONETARY=en_US.utf8 LC_MESSAGES=en_US.utf8
[7] LC_PAPER=en_US.utf8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] data.table_1.12.8
loaded via a namespace (and not attached):
[1] compiler_3.6.3