Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
# [1] 5 1 2 3 4
```

28. `fread()` now also supports "0" and "1" in `na.strings`, [#2927](https://github.com/Rdatatable/data.table/issues/2927). Previously this was not permitted since "0" and "1" can be recognized as boolean values. Note that it is still not permitted to use "0" and "1" in `na.strings` in combination with `logical01 = TRUE`. Thanks to @msgoussi for the request, and Benjamin Schwendinger for the PR.
## BUG FIXES

1. `by=.EACHI` when `i` is keyed but `on=` different columns than `i`'s key could create an invalidly keyed result, [#4603](https://github.com/Rdatatable/data.table/issues/4603) [#4911](https://github.com/Rdatatable/data.table/issues/4911). Thanks to @myoung3 and @adamaltmejd for reporting, and @ColeMiller1 for the PR. An invalid key is where a `data.table` is marked as sorted by the key columns but the data is not sorted by those columns, leading to incorrect results from subsequent queries.
Expand Down
8 changes: 6 additions & 2 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -7848,10 +7848,14 @@ read_table = function(str, ...) {
test(1552.1, fread(str, na.strings="#N/A"), read_table(str, na.strings="#N/A"))
test(1552.2, fread(str, na.strings=c("#N/A", "-999")), read_table(str, na.strings=c("#N/A", "-999")))
test(1552.3, fread(str, na.strings=c("#N/A", "-999", "+1")), read_table(str, na.strings=c("#N/A", "-999", "+1")))
test(1552.4, fread(str, na.strings=c("#N/A", "-999", "+1", "1")),
error="NAstring <<1>> is recognized as type boolean.*not permitted")
test(1552.4, fread(str, na.strings=c("#N/A", "-999", "+1", "1")), read_table(str, na.strings=c("#N/A", "-999", "+1", "1"))) # enabled by FR #2927
test(1552.5, fread(str, na.strings=c("#N/A", "-999", "FALSE")), error="NAstring <<FALSE>>.*boolean.*not permitted")
test(1552.6, fread("A\n1.0\n2\n-", na.strings=c("-")), data.table(A=c(1.0, 2.0, NA)))
test(1552.7, fread(str, na.strings=c("#N/A", "-999", "+1", "1"), logical01=TRUE),
error="NAstring <<1>> and logical01=TRUE.*not permitted")
str = "a,b,c\n0,1,2\n1,0,2"
test(1552.8, fread(str, na.strings = "0"), data.table(a=c(NA,1L), b=c(1L,NA), c=c(2L,2L)))
test(1552.9, fread(str, na.strings = c("0","1")), data.table(a=c(NA,NA), b=c(NA,NA), c=c(2L,2L)))

# FR #1177: 'quote' option of 'print.data.table'
DT1 <- data.table(s1=paste(" ",LETTERS[1:5],sep=""),s2=LETTERS[1:5])
Expand Down
5 changes: 3 additions & 2 deletions src/fread.c
Original file line number Diff line number Diff line change
Expand Up @@ -1287,9 +1287,10 @@ int freadMain(freadMainArgs _args) {
STOP(_("freadMain: NAstring <<%s>> has whitespace at the beginning or end"), ch);
if (strcmp(ch,"T")==0 || strcmp(ch,"F")==0 ||
strcmp(ch,"TRUE")==0 || strcmp(ch,"FALSE")==0 ||
strcmp(ch,"True")==0 || strcmp(ch,"False")==0 ||
strcmp(ch,"1")==0 || strcmp(ch,"0")==0)
strcmp(ch,"True")==0 || strcmp(ch,"False")==0)
STOP(_("freadMain: NAstring <<%s>> is recognized as type boolean, this is not permitted."), ch);
if ((strcmp(ch,"1")==0 || strcmp(ch,"0")==0) && args.logical01)
STOP(_("freadMain: NAstring <<%s>> and logical01=%s, this is not permitted."), ch, args.logical01 ? "TRUE" : "FALSE");
char *end;
errno = 0;
(void)strtod(ch, &end); // careful not to let "" get to here (see continue above) as strtod considers "" numeric
Expand Down