Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
DavidArenburg opened this issue Jul 8, 2015 · 1 comment
Closed

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

DavidArenburg opened this issue Jul 8, 2015 · 1 comment
Assignees
Milestone

Comments

@DavidArenburg
Copy link
Member

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

@DavidArenburg
Copy link
Member Author

Forgot to mention that this is reproducible only on the devel version (v 1.9.5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants