Skip to content

get corrupts data.table object with a list column #1212

@DavidArenburg

Description

@DavidArenburg

Regarding this post, consider

require(data.table)
set.seed(123)
dt <- data.table(a=c("abc", "def", "ghi"), b=runif(3))
dt[, c:=list(list(data.table(d=runif(1), e=runif(1))))]
dt
#      a         b            c
#1: abc 0.2875775 <data.table>
#2: def 0.7883051 <data.table>
#3: ghi 0.4089769 <data.table>

dt[, get("c")] ## <<-- not sure if print bug
# Error in FUN(X[[1L]], ...) : 
#   Invalid column: it has dimensions. Can't format it. If it's the result of data.table(table()), use as.data.table(table()) instead.

dt ## <<- why isn't this being printed?
# Error in FUN(X[[1L]], ...) : 
#   Invalid column: it has dimensions. Can't format it. If it's the result of data.table(table()), use as.data.table(table()) instead.

Interestingly, this still works:

rbindlist(dt[, get(var)])
#           V1        V2
#1: 0.8830174 0.9404673
#2: 0.8830174 0.9404673
#3: 0.8830174 0.9404673

Another scenario

set.seed(123)
dt <- data.table(a=c("abc", "def", "ghi"), b=runif(3))
dt[, c:=list(list(data.table(d=runif(1), e=runif(1))))]
var <- "c" 
rbindlist(dt[[var]])
##           d         e
## 1: 0.8830174 0.9404673
## 2: 0.8830174 0.9404673
## 3: 0.8830174 0.9404673

rbindlist(dt[, get(var)])
##           V1        V2
## 1: 0.8830174 0.9404673
## 2: 0.8830174 0.9404673
## 3: 0.8830174 0.9404673

rbindlist(dt[[var]])
##           V1        V2        ## <<-- what happened to the column names?
## 1: 0.8830174 0.9404673
## 2: 0.8830174 0.9404673
## 3: 0.8830174 0.9404673

Seems like column names were lost

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions