Skip to content

key argument is ignored within setDT if DT is already a data.table #1169

@DavidArenburg

Description

@DavidArenburg

It's probably not a big deal, but sometimes you are not aware your object is already a data.table (like you've read it using fread) and this could be quite mind blowing until you realize what's going on

library(data.table)
DT <- data.table(A = 1:4, B = 5:8)
setDT(DT, key = "A")
key(DT)
## NULL

I think that a quick fix is just to add

 if (!is.null(key)) setkeyv(x, key)

after this line

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions