You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The comparison of two data.tables yields a matrix for which the value returned by colnames() changes when columns are added by reference to the leftmost data.table which the matrix was created from. Specifically, consider that a <- b <- data.table(X=1:2). Then, x <- a==b; print(x) returns a matrix
X
[1,] TRUE
[2,] TRUE
and colnames(x) returns "X" as expected. Adding the column Y as a[, Y:=1] results in colnames(x) returning print(x)returning"X" "Y", even though print(x)still returns the same as above. Further, this does not happen if the column is added asa$Y <- 1` or if the column is added to b instead. I have not managed to reproduce the problem with data.frames, thus the chances are this is a problem that can be solved here.
> ## The section below reproduces the problem
> a <- b <- data.table(X=1:2)
> x <- a==b
> print(x)
X
[1,] TRUE
[2,] TRUE
> colnames(x)
[1] "X"
>
> ## Adding a column to a by reference causes the column names of x to change.
> a[, Y:=1]
> print(x)
X
[1,] TRUE
[2,] TRUE
> colnames(x)
[1] "X" "Y"
>
#Output of sessionInfo()
R version 3.6.2 (2019-12-12)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.6 LTS
The comparison of two data.tables yields a matrix for which the value returned by colnames() changes when columns are added by reference to the leftmost data.table which the matrix was created from. Specifically, consider that
a <- b <- data.table(X=1:2)
. Then,x <- a==b; print(x)
returns a matrixand
colnames(x)
returns"X"
as expected. Adding the column Y asa[, Y:=1]
results incolnames(x)
returning print(x)returning
"X" "Y", even though
print(x)still returns the same as above. Further, this does not happen if the column is added as
a$Y <- 1` or if the column is added to b instead. I have not managed to reproduce the problem with data.frames, thus the chances are this is a problem that can be solved here.#
Minimal reproducible example
#
Output of sessionInfo()
R version 3.6.2 (2019-12-12)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.6 LTS
Matrix products: default
BLAS: /usr/lib/openblas-base/libblas.so.3
LAPACK: /usr/lib/libopenblasp-r0.2.18.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=fi_FI.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=fi_FI.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=fi_FI.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=fi_FI.UTF-8 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.2
The text was updated successfully, but these errors were encountered: