Skip to content
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@

42. `DT[factor("id")]` now works rather than error `i has evaluated to type integer. Expecting logical, integer or double`, [#1632](https://github.com/Rdatatable/data.table/issues/1632). `DT["id"]` has worked forever by automatically converting to `DT[.("id")]` for convenience, and joins have worked forever between char/fact, fact/char and fact/fact even when levels mismatch, so it was unfortunate that `DT[factor("id")]` managed to escape the simple automatic conversion to `DT[.(factor("id"))]` which is now in place. Thanks to @aushev for reporting, and Matt Dowle for the fix.

43. All-NA character key columns could segfault, [#5070](https://github.com/Rdatatable/data.table/issues/5070). Thanks to @JorisChau for reporting and Benjamin Schwendinger for the fix.

## NOTES

1. New feature 29 in v1.12.4 (Oct 2019) introduced zero-copy coercion. Our thinking is that requiring you to get the type right in the case of `0` (type double) vs `0L` (type integer) is too inconvenient for you the user. So such coercions happen in `data.table` automatically without warning. Thanks to zero-copy coercion there is no speed penalty, even when calling `set()` many times in a loop, so there's no speed penalty to warn you about either. However, we believe that assigning a character value such as `"2"` into an integer column is more likely to be a user mistake that you would like to be warned about. The type difference (character vs integer) may be the only clue that you have selected the wrong column, or typed the wrong variable to be assigned to that column. For this reason we view character to numeric-like coercion differently and will warn about it. If it is correct, then the warning is intended to nudge you to wrap the RHS with `as.<type>()` so that it is clear to readers of your code that a coercion from character to that type is intended. For example :
Expand Down
9 changes: 9 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -4155,6 +4155,10 @@ DT = data.table(A=c(utf8_strings, latin1_strings), B=1:4)
test(1162.21, is.sorted(DT), FALSE)
setkey(DT)
test(1162.22, is.sorted(DT), TRUE)
# Issue #5070
DT = data.table(x2 = rep(NA_character_, 2))
test(1162.23, is.sorted(DT))
test(1162.24, is.sorted(rep(NA_character_, 2)))

# FR #351 - last on length=0 arguments
x <- character(0)
Expand Down Expand Up @@ -18141,4 +18145,9 @@ DT = data.table(A=letters[1:3], B=4:6, key="A")
test(2215.1, DT["b", B], 5L) # has worked forever
test(2215.2, DT[factor("b"), B], 5L) # now works too, joining fact/fact, char/fact and fact/char have plenty of tests

# segfault on merge keyed all-NA_character_ due to is.sorted, #5070
DT1 = data.table(x1 = rep(letters[1:4], each=3), x2=NA_character_, key="x2")
DT2 = data.table(x1 = letters[1:3])
test(2216.1, DT1[DT2, on="x1"][,.(x1,x2)], DT1[1:9]) # segfault in v1.14.0
test(2216.2, merge(DT1, DT2, by="x1")[,.(x1,x2)], setkey(DT1[1:9], x1)) # ok before but included for completeness verbatim from issue

1 change: 1 addition & 0 deletions src/forder.c
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,7 @@ SEXP issorted(SEXP x, SEXP by)
SEXP *xd = STRING_PTR(x);
i = 0;
while (i<n && xd[i]==NA_STRING) i++;
if (i==n) break; // xd consists only of NA_STRING #5070
bool need = NEED2UTF8(xd[i]);
Comment thread
mattdowle marked this conversation as resolved.
i++; // pass over first non-NA_STRING
while (i<n) {
Expand Down