Skip to content

fread: Improve validation of the dec argument#7738

Open
mcol wants to merge 1 commit intoRdatatable:masterfrom
mcol:issue_7737
Open

fread: Improve validation of the dec argument#7738
mcol wants to merge 1 commit intoRdatatable:masterfrom
mcol:issue_7737

Conversation

@mcol
Copy link
Copy Markdown
Contributor

@mcol mcol commented May 5, 2026

Fixes #7737 and adds a test.

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

codecov Bot commented May 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.04%. Comparing base (da0d15e) to head (f79fc6e).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7738   +/-   ##
=======================================
  Coverage   99.04%   99.04%           
=======================================
  Files          87       87           
  Lines       17058    17058           
=======================================
  Hits        16895    16895           
  Misses        163      163           

☔ View full report in Codecov by Sentry.
📢 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
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
}
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")).

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_

2 participants