fread: Improve validation of the dec argument - #7738
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7738 +/- ##
=======================================
Coverage 99.01% 99.01%
=======================================
Files 88 88
Lines 17288 17288
=======================================
Hits 17118 17118
Misses 170 170 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| 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") |
There was a problem hiding this comment.
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.
| } | ||
| 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) |
There was a problem hiding this comment.
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")).
There was a problem hiding this comment.
The case dec = letters is already handled by the stopifnot() just before it. But using one of your variations is nicer anyway.
ben-schwen
left a comment
There was a problem hiding this comment.
change LGTM, news is missing (before we can merge it)
Fixes #7737 and adds a test.