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

Problem with colnames in derived matrix from data.table comparison #4323

Closed
eyherabh opened this issue Mar 27, 2020 · 0 comments · Fixed by #4328
Closed

Problem with colnames in derived matrix from data.table comparison #4323

eyherabh opened this issue Mar 27, 2020 · 0 comments · Fixed by #4328
Milestone

Comments

@eyherabh
Copy link
Contributor

eyherabh commented Mar 27, 2020

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.

# Minimal reproducible example

> ## 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

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

@jangorecki jangorecki added this to the 1.12.9 milestone Mar 27, 2020
@jangorecki jangorecki removed this from the 1.12.11 milestone Jun 17, 2020
@mattdowle mattdowle added this to the 1.12.9 milestone Jun 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants