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
{{ message }}
Repository navigation
Strange behavior on dt[J(d2), a := b, nomatch = 0] #1092
I am using a magnificent data.table package version 1.9.4. Thanks a lot for such useful software masterpiece.
In example below, data.table complains that columns o and n are of different length while I don't see a reason why they should be different.
library(data.table)
tr = data.table(k = c(0, 2, 3, 7), o = "b", key = "k")
en = data.table(k = c(1, 2, 3, 4, 5), n = c("n1", "n2", "n3", "n4", "n5"), key = "k")
tr_copy = copy(tr)
## Gives a warning about recycling and produces wrong result,
## why `o` and `n` of a different length, aren't they supposed to be equal after join?
tr_copy[en, o := n, nomatch = 0]
## Warning message: In `[.data.table`(tr_copy, en, `:=`(o, n), nomatch = 0) : Supplied 2 items to be assigned to 5 items of column 'o' (recycled leaving remainder of 1 items).
#######################################################
#######################################################
tr_copy = copy(tr)
## No error and gives correct result, seems counterintuitive
tr[en, o := n, nomatch = NA]
I am also extensively using this wonderful package and I encoutered the same kind of strange behaviour, but in addition to what riabusan said I would add two things :
1) First, sometimes you don't even get a warning which makes it really tricky. For instance if I slightly modify riabusan's example by adding 0, 6, 7 and the corresponding n0, n6, n7 into his "en" variable it gives :
Activity
jangorecki commentedon Mar 23, 2015
Good MRE! same on
1.9.5.cguill95 commentedon Mar 25, 2015
Hi,
I am also extensively using this wonderful package and I encoutered the same kind of strange behaviour, but in addition to what riabusan said I would add two things :
1) First, sometimes you don't even get a warning which makes it really tricky. For instance if I slightly modify riabusan's example by adding 0, 6, 7 and the corresponding n0, n6, n7 into his "en" variable it gives :
arunsrinivasan commentedon May 10, 2015
Thanks for the reports. Now fixed, although (the current behaviour of)
nomatch=0Lhas no effect with:=.