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 upcbind fails if input is a 0-column data frame. #3334
Comments
|
This could be simplified to library(data.table)
data.table(data.table(a=1), data.table())
#Error in data.table::data.table(...) :
# Item 2 has no length. Provide at least one item (such as NA, NA_integer_ etc) to be repeated to match the 1 row in the longest column. Or, all columns can be 0 length, for insert()ing rows into.in data.table we do not allow to have non-0 rows for 0 columns, but of course such usage could be handled nicely. |
Credit goes to @austin3dickey for diagnosing this and @hcui10 for digging further.
When one of the arguments is a 0-column data frame, the overloaded function, cbind() fails with
Error in data.table::data.table(...) : Item 2 has no length. Provide at least one item (such as NA, NA_integer_ etc) to be repeated to match the 5 rows in the longest column. Or, all columns can be 0 length, for insert()ing rows into.Reproducible Example
Root Cause Diagnosis
This seems to occur when
cbind.data.frameconverts adata.frameinto adata.table.This causes the number of rows to change.
Which fails below since the number of rows is now 0.
Original Point of Failure
This was originally discovered when attempting to run the following.