Skip to content

fread: Improve validation of the dec argument - #7738

Merged
ben-schwen merged 9 commits into
Rdatatable:masterfrom
mcol:issue_7737
Jul 30, 2026
Merged

fread: Improve validation of the dec argument#7738
ben-schwen merged 9 commits into
Rdatatable:masterfrom
mcol:issue_7737

Conversation

@mcol

@mcol mcol commented May 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #7737 and adds a test.

@mcol
mcol requested a review from MichaelChirico as a code owner May 5, 2026 10:57
@codecov

codecov Bot commented May 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.01%. Comparing base (7373a7a) to head (653efdd).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7738   +/-   ##
=======================================
  Coverage   99.01%   99.01%           
=======================================
  Files          88       88           
  Lines       17288    17291    +3     
=======================================
+ Hits        17118    17121    +3     
  Misses        170      170           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread inst/tests/tests.Rraw Outdated
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.

Comment thread R/fread.R Outdated
}
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.

@ben-schwen ben-schwen left a comment

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.

change LGTM, news is missing (before we can merge it)

@mcol

mcol commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

It's ready to go from my side.

Comment thread R/fread.R Outdated
Comment thread inst/tests/tests.Rraw Outdated
rm(inner, DT, DT2)

## validation of dec argument
test(7737.1, fread(input = "whatever.csv", dec = NA_character_), error=base_messages$stopifnot("nchar(dec) == 1L"))

@ben-schwen ben-schwen Jul 30, 2026

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.

Suggested change
test(7737.1, fread(input = "whatever.csv", dec = NA_character_), error=base_messages$stopifnot("nchar(dec) == 1L"))
test(2382.1, fread(input = "whatever.csv", dec = NA_character_), error='dec= must be a single non-NA character, or "auto".')

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.

Unfortunately, Github does not let me push this one. Test numbers need to be in ascending order because we check for this.

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.

Done.

Comment thread inst/tests/tests.Rraw Outdated
rm(inner, DT, DT2)

## validation of dec argument
test(2382.1, fread(input = "whatever.csv", dec = NA_character_), error='dec= must be a single non-NA character, or "auto".')

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.

Apparently I mixed an extra , in. sorry for that.
Also can you move this as test(1439.1), adjust test 1439 and add the number of the issue of the comment of ## validation of dec argument

@ben-schwen
ben-schwen merged commit 0d338a9 into Rdatatable:master Jul 30, 2026
13 of 14 checks passed
@ben-schwen

Copy link
Copy Markdown
Member

TY!

@mcol
mcol deleted the issue_7737 branch July 30, 2026 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dec argument of fread() doesn't validate against NA_character_

3 participants