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.Dismiss alert
library(data.table)
temp1<- data.table(x=factor("a"))
split(temp1, by="x")
# Error: is.data.table(x) is not TRUE# this workstemp2<- data.table(.x=factor("a"))
split(temp2, by=".x")
# this works as welltemp3<- data.table(x="a")
split(temp3, by="x")
So the problem only emerges if the splitting variable is called 'x' and it is a factor. The problem can be rooted back to thistemp = eval(dtq) call in split.data.table. In the dtq unevaluated call, make.levels(x, cols=.cols, sorted=.sorted) finds the 'x' variable instead of the 'x' data.table. A quick fix is to write make.levels(.___x, cols=.cols, sorted=.sorted) instead, and do a temporary assignment .___x <- x before temp = eval(dtq).
The previous report was not totally correct. 'x' must not be the splitting variable:
temp5<- data.table(y=factor("a"), x=1)
split(temp5, by="y")
# Error: is.data.table(x) is not TRUE
However, I think the diagnosis given above is still correct, and the proposed fix eliminates the bug. I can submit a PR but maybe you guys have a less hackish solution for this.
Thanks for the report, and thanks for finding solution. PR is very welcome.
Note that split.data.table has verbose argument which I specifically added so the calls constructed and run with eval can be easily investigated.
Just found the following bug:
So the problem only emerges if the splitting variable is called 'x' and it is a factor. The problem can be rooted back to this
temp = eval(dtq)
call insplit.data.table
. In thedtq
unevaluated call,make.levels(x, cols=.cols, sorted=.sorted)
finds the 'x' variable instead of the 'x' data.table. A quick fix is to writemake.levels(.___x, cols=.cols, sorted=.sorted)
instead, and do a temporary assignment.___x <- x
beforetemp = eval(dtq)
.SessionInfo (the bug is also present in 1.11.8):
The text was updated successfully, but these errors were encountered: