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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@

18. `example(local=TRUE)` where the example uses `[.data.table` works again (e.g. `example(':=', package='data.table', local=TRUE, echo=FALSE)`), [#7855](https://github.com/Rdatatable/data.table/issues/7855) re-fixing [#2972](https://github.com/Rdatatable/data.table/issues/2972). Thanks @michaelChirico for the fix.

19. `fread()` returns a clearer error message when `dec = NA` is used, [#7737](https://github.com/Rdatatable/data.table/issues/7737). Thanks @mcol for the report and the fix.

### Notes

1. {data.table} now depends on R 3.5.0 (2018).
Expand Down
6 changes: 5 additions & 1 deletion R/fread.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ yaml=FALSE, tmpdir=tempdir(), tz="UTC")
else stopifnot( nchar(sep)==1L ) # otherwise an actual character to use as sep
}
stopifnot( is.character(dec), length(dec)==1L)
if (dec == "auto") dec = "" else stopifnot(nchar(dec) == 1L)
if (identical(dec, "auto")) {
dec = ""
} else if (!is.character(dec) || length(dec) != 1L || is.na(dec) || nchar(dec) != 1L) {
stopf('dec= must be a single non-NA character or "auto".')
}
# handle encoding, #563
if (length(encoding) != 1L || !encoding %chin% c("unknown", "UTF-8", "Latin-1")) {
stopf("Argument 'encoding' must be 'unknown', 'UTF-8' or 'Latin-1'.")
Expand Down
5 changes: 3 additions & 2 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -6449,8 +6449,9 @@ for (t in seq_len(nrow(all))) {

}

# fread dec=',' e.g. France
test(1439, fread("A;B\n1;2,34\n", dec="12"), error=base_messages$stopifnot("nchar(dec) == 1L"))
# validation of dec argument, issue #7738
test(1439.1, fread("A;B\n1;2,34\n", dec="12"), error='dec= must be a single non-NA character or "auto".')
test(1439.2, fread(input = "whatever.csv", dec = NA_character_), error='dec= must be a single non-NA character or "auto".')
test(1440, fread("A;B\n8;2,34\n", dec="1"), data.table(A=8L, B="2,34"))
test(1441, fread("A;B\n8;2,34\n", dec=","), data.table(A=8L, B=2.34))
test(1442, fread("A;B\n1;2,34\n", sep=".", dec="."), error="sep == dec ('.') is not allowed")
Expand Down
Loading