[datatable-help] Change names of a data.table, key stays old name

Chris Neff caneff at gmail.com
Thu Aug 4 22:05:40 CEST 2011


Quick example:

> DT <- data.table(x=1:10,y=1:10)

> key(DT) <- "x"

> names(DT) <- c("a", "b", "c")

> key(DT)
[1] "x"


This doesn't seem to be right.  An error happens if I do some things:

> x[J(5)]
Error in `[.data.table`(x, J(5)) :
  sorted columns of x don't exist in the colnames. data.table is not a
valid data.table

But other things work fine still:

> x[a == 5, ]
[1,] 5 6 6


When names get changed, the key names should be updated to reflect that, no?

-Chris


More information about the datatable-help mailing list