You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.
I think I found a bug case where data.table does not work with ggplot.
Here's an example:
dt = data.table()
dt[, x := seq(1,100)]
dt[, y := seq(100,1)]
1: 1 100
2: 2 99
3: 3 98
4: 4 97
5: 5 96
6: 6 95
# generate ggplot
ggplot(dt, aes(x,y)) + geom_point()
Error in `$<-.data.frame`(x, name, value) :
replacement has 1 row, data has 0
A workaround was
dt %>% setDF %>% setDT # convert to DF and convert it back
ggplot(dt, aes(x,y)) + geom_point() # now it works
which doesn't seem convenient.
I'm not certain if it is coming from data.table or ggplot, for plot(dt) just works fine, but I guessed it was from data.table side because setDT somehow resolves the issue. Or was I naive to use empty data.table from scratch?
The text was updated successfully, but these errors were encountered:
It seems like we need to either prevent users from starting from an empty data.table or update row.names on assignment when the number of rows is greater than the current number of rows of dt. And while a null.data.table seems to be the main way where this issue would be, here are some other edge cases:
## 0 row data table with assignmentdt= data.table(x= integer())
#Empty data.table (0 rows and 2 cols): x,y## 1 row data.table with assignmentdt= data.table(x=1L)
#Error in `[.data.table`(dt, , `:=`(y, 1:2)) : # Supplied 2 items to be assigned to 1 items of column 'y'. If you wish to 'recycle' the RHS please use rep() to make this intent clear to readers of your code.## 2 row data.table with length(0) assignmentdt= data.table(x=1:2)
dt[, y:= integer()]
## x y##1: 1 NA## 2: 2 NA