Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upas.data.table.matrix keeps row names for null data tables #3149
Comments
|
I can't replicate this behavior:
|
|
@sritchie73 You are doing something slightly different then @mllg imo With
I think the problem stems from the line of the code of the
As you can see, in the third line from the end the rownames are set with the number of rows of the matrix A possible solution might be to set the |
|
Wouldn't it make more sense to just grab the number of rows from the new data.table? I.e. change the fourth last line to:
|
|
interesting that
But as
that the end result is going to be I'm not 100% sure what the "right" result is, but if it's going to be a
|
|
@MichaelChirico suggestion was the simplest and well addressing the issue. I pushed it in PR and added few more tests for other edge cases so we are more future proof. |
|
This problem also arises with
|
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.