Consider this example:
M = matrix(1:3, nrow = 3)
M = M[, integer(0)]
DT = as.data.table(M) # null data table
The resulting object DT is a "Null data.table" with dimensions c(0,0). This deviates from as.data.frame, but this is documented.
> nrow(DT)
[1] 0
> dim(DT)
[1] 0 0
Confusingly, the null data.table still has rownames:
rownames(DT)
[1] "1" "2" "3"
This is problematic, because the dimensions of a data.frame is calculated using the rownames:
> base::dim.data.frame(DT)
[1] 3 0
Of course there is a S3 method dim.data.table which returns c(0, 0). However, you get the wrong dimensions in C/C++ code.
I wonder if there is any advantage in keeping the row names. I first thought they are stored for the conversion of data.tables to data.frames (as.data.frame / setDF), but the row names seem to be ignored here, too.
Consider this example:
The resulting object
DTis a "Null data.table" with dimensionsc(0,0). This deviates fromas.data.frame, but this is documented.Confusingly, the null data.table still has rownames:
This is problematic, because the dimensions of a
data.frameis calculated using the rownames:Of course there is a S3 method
dim.data.tablewhich returnsc(0, 0). However, you get the wrong dimensions in C/C++ code.I wonder if there is any advantage in keeping the row names. I first thought they are stored for the conversion of data.tables to data.frames (
as.data.frame/setDF), but the row names seem to be ignored here, too.