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
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 usingfread) and this could be quite mind blowing until you realize what's going onI think that a quick fix is just to add
after this line