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
Somehow, the issue has reappeared (#2540). The old bugfix by Matt (a0b27e8) must have fallen victim to code refactoring.
Existing tests do not spot the issue reliably.
Submitted by: Timothee Carayol; Assigned to: Nobody; R-Forge link
I say it's scary because it returns no error and is potentially quite difficult to detect in existing code..
FYI I tried this on data.table 1.8.2 and R 2.14.1.
A <- data.table(
keyvar=rev(letters[1:10]),
count=1:10
)
A[, c(
'count1',
'count2'
) := count, with=F
]
A
1: j 1 1 1
2: i 2 2 2
3: h 3 3 3
4: g 4 4 4
5: f 5 5 5
6: e 6 6 6
7: d 7 7 7
8: c 8 8 8
9: b 9 9 9
10: a 10 10 10
All looks good.
Let's make a copy of A; call it B. We'll use it later on.
B <- copy(A)
Now let's set a key on "keyvar" in A:
setkeyv(A, 'keyvar')
A
1: a 10 1 1
2: b 9 2 2
3: c 8 3 3
4: d 7 4 4
5: e 6 5 5
6: f 5 6 6
7: g 4 7 7
8: h 3 8 8
9: i 2 9 9
10: j 1 10 10
That's the scary bit. "keyvar" and "count" got sorted nicely, but "count1" and "count2" are now matched to wrong rows.
Let's try the same thing on the copy of A that we made earlier..
setkeyv(B, 'keyvar')
B
1: j 1 1 1
2: i 2 2 2
3: h 3 3 3
4: g 4 4 4
5: f 5 5 5
6: e 6 6 6
7: d 7 7 7
8: c 8 8 8
9: b 9 9 9
10: a 10 10 10
That's fine!
I.e. whatever was wrong with A, is fixed in its copy B.
The text was updated successfully, but these errors were encountered: