-
Notifications
You must be signed in to change notification settings - Fork 985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
as.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
DT
is 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.frame
is calculated using the rownames:Of course there is a S3 method
dim.data.table
which 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.The text was updated successfully, but these errors were encountered: