Skip to content

Arrays of certain dimension returned from .() do not preserve names as expected #5367

Description

@ccampbell1987

Hello,
I could not find anything related to this in NEWS. I feel that in the case of an array or matrix of a compatible dimension (e.g. nx1 or 1x1) should behave similarly to a vector and preserve the intended name in .(). Adding ".V1" to the intended name below felt unexpected.

Thanks,
Christopher

# Minimal reproducible example; please be sure to set verbose=TRUE where possible!

library(data.table)
DT <- data.table(Counts = c(10, 20), 
                 Severity = c(1,2))

DT[,.(Severity %*% Counts)]
DT[,class(Severity %*% Counts)]
DT[,dim(Severity %*% Counts)]

DT[,.(New_name = Severity %*% Counts)] # name is New_name.V1
DT[,.(New_name = Severity * Counts)] # name is New_name

# Output of sessionInfo()
R version 4.0.4 (2021-02-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Pop!_OS 21.10

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] data.table_1.14.2

loaded via a namespace (and not attached):
[1] compiler_4.0.4 tools_4.0.4

Activity

  1. MichaelChirico commented on Jul 14, 2025

    @MichaelChirico
    Member

    Here's another case fixed by #4363, with result on current master:

    DT[,.(New_name = Severity %*% Counts)]
    #    New_name
    #       <num>
    # 1:       50

    The caveat is that, because this was a breaking change, it will only become the default gradually. Opt in to this new behavior after #7158.

  2. added a commit that references this issue on Jul 14, 2025
    cb10974
  3. added a commit that references this issue on Jul 15, 2025
    2675539
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions