check_*() error on empty input when allow_empty = FALSE (#30) - #33
Merged
Conversation
Previously, empty but correctly-typed input (e.g. character(0), numeric(0), 0-row/0-col data frames) silently passed check_*() class and type checks even under the default allow_empty = FALSE. The empty-handling guard now errors in that case and only returns invisibly when allow_empty = TRUE. Updated the affected guard sites uniformly, added tests covering empty input for all affected functions, fixed a stale test that asserted the old behavior, and updated the script changelog and last-updated field.
Melkiades
force-pushed
the
30_allow_empty@main
branch
from
July 1, 2026 12:07
0b26b5a to
69bd6cd
Compare
Contributor
|
✅ All contributors have signed the CLA |
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
Contributor
Author
|
recheck |
12 tasks
There was a problem hiding this comment.
Pull request overview
Updates {standalone} input validation so check_*() helpers consistently error on empty inputs when allow_empty = FALSE, aligning behavior with the documented/default expectation and Issue #30.
Changes:
- Make empty-input handling explicit across multiple
check_*()functions (error by default; return invisibly whenallow_empty = TRUE). - Update/add test coverage to assert the new empty-input behavior.
- Document the behavior change in the standalone script changelog and
NEWS.md.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| R/standalone-checks.R | Tightens guard logic so empty inputs no longer silently pass type/class checks when allow_empty = FALSE. |
| tests/testthat/test-standalone-checks.R | Updates existing expectations and adds a regression test block for empty-input behavior. |
| NEWS.md | Notes the user-visible behavior change for check_*() functions. |
Suppressed comments (3)
R/standalone-checks.R:626
- With the new empty-input erroring behavior, the empty-branch abort currently reuses
message("must be numeric."), which is confusing fornumeric(0)because it is numeric. Use a dedicated message for the empty-input branch so the error explains the actual failure condition.
cli::cli_abort(message, class = c(class, "standalone-checks"), call = call, .envir = envir)
R/standalone-checks.R:508
- Similar to
check_numeric(): in the empty-input branch this abort reuses the generalmessage, which is confusing forinteger(0)because it satisfies the "integer vector" predicate (rlang::is_integerish()) but is rejected due to emptiness. Using an explicit empty-input message here will make the failure reason clear.
cli::cli_abort(message, class = c(class, "standalone-checks"), call = call, .envir = envir)
R/standalone-checks.R:540
- The default error message text is ungrammatical ("must an scalar integer"). This will surface in snapshots/consumer logs and is easy to correct while touching this function.
# if empty: return invisibly when allowed, otherwise error
if (rlang::is_empty(x)) {
if (isTRUE(allow_empty)) {
return(invisible(x))
}
cli::cli_abort(message, class = c(class, "standalone-checks"), call = call, .envir = envir)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- fix 'must an' typo in check_integerish/check_scalar_integerish messages - check_scalar_integerish() now uses its own condition class instead of check_integerish, so callers can catch scalar failures specifically - add empty-input regression tests for check_scalar_integerish and check_length - update snapshot for the corrected message text
shajoezhu
enabled auto-merge (squash)
August 10, 2026 16:08
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes are proposed in this pull request?
check_*()functions now error on empty input whenallow_empty = FALSE(previously empty but correctly-typed input silently passed class/type checks). (allow_empty updates #30, @Melkiades)Empty but correctly-typed input (e.g.
character(0),numeric(0), 0-row/0-column data frames) previously fell through the empty-handling guard and silently passed the downstream class/type checks even under the defaultallow_empty = FALSE. The guard is now explicit: it returns invisibly only whenallow_empty = TRUE, otherwise it errors. This was applied uniformly across all affected guard sites (check_class(),check_length(),check_range(),check_binary(),check_formula_list_selector(),check_integerish(),check_scalar_integerish(),check_numeric(), and the delegatingcheck_data_frame()/check_logical()).Downstream consumers (
cards,cardx,crane,pager) were scanned: no call site passes a legitimately-empty argument withoutallow_empty = TRUE, and no consumer test relies on the old silent-pass behavior, so this change is safe.Reference GitHub issue associated with pull request. closes #30
Pre-review Checklist (if item does not apply, mark is as complete)
usethis::pr_merge_main()last-updatedfield has been updated.devtools::test_coverage()Reviewer Checklist (if item does not apply, mark is as complete)
last-updatedfield has been updated.pkgdown::build_site(). Check the R console for errors, and review the rendered website.devtools::test_coverage()When the branch is ready to be merged: