Skip to content

data.table(vector, matrix) can return duplicate column names #3193

@MichaelChirico

Description

@MichaelChirico
data.table(1:5, matrix(6:15, nrow = 5L))
#    V1 V1 V2
# 1:  1  6 11
# 2:  2  7 12
# 3:  3  8 13
# 4:  4  9 14
# 5:  5 10 15

Not ideal to be creating data.tables with duplicate names from the get-go... those names should be V2_1 and V2_2 i guess.

Fixes with check.names but I'm not sure creating duplicates like this by default is the right behavior; my only hesitation is I'm sure there are other more complicated cases that are still creating duplicates even if we fix this.

The fix to this specific issue can be very simple, however, just add 7 characters to this line:

https://github.com/Rdatatable/data.table/blob/master/R/data.table.R#L98

if (any(tt)) namesi[tt] = paste0("V", i, '_', which(tt))

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions