Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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: 1 addition & 1 deletion R/fread.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ 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 (!is.na(dec) && dec == "auto") dec = "" else stopifnot(nchar(dec) == 1L)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this also gives the same "ugly" error for dec = letters, so might as well change to if (isTRUE(dec == "auto")) or if (identical(dec, "auto")).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The case dec = letters is already handled by the stopifnot() just before it. But using one of your variations is nicer anyway.

# 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
3 changes: 3 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -21605,3 +21605,6 @@ test(2370.2, yearmon(x, format="numeric"), yearmon(x)) # numeric is the default
test(2370.3, yearmon(x, format="character"), c("1111M11", "2019M01", "2019M02", "2019M03", "2019M12", "2020M02", "2020M03", "2020M12", "2040M01", "2040M12", "2100M03", NA_character_))
test(2370.4, yearmon("2016-08-03 01:02:03.45", format="character"), "2016M08")
test(2370.5, yearmon(NA, format="character"), NA_character_)

## validation of dec argument
test(7737.1, fread(input = "whatever.csv", dec = NA_character_), error="nchar(dec) == 1L is not TRUE")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this error comes from base, not data.table, so the test is fragile. Look around and especially near the top of the test file for our proposed way to structure such tests.

Loading