Skip to content

Commit 0618a4b

Browse files
committed
Add allow_na to check_logical()
I think this finishes everything for r-lib#1724. The rest was fixed in r-lib#1742. A separate PR, r-lib#1745, additionally adds `allow_empty`, but I wanted to leave that out of this to make it easier to review the one small, relevant change. I didn't add add anything to NEWS.md, since the standalone kinda has its own news. I'm not sure if it would be better to also mention is in the main NEWS.md to make it more visible. Fixes r-lib#1724.
1 parent 7371bac commit 0618a4b

File tree

3 files changed

+14
-491
lines changed

3 files changed

+14
-491
lines changed

R/standalone-types-check.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#
1010
# ## Changelog
1111
#
12+
# 2025-09-19:
13+
# - `check_logical()` gains an `allow_na` argument (@jonthegeek, #1724)
14+
#
1215
# 2024-08-15:
1316
# - `check_character()` gains an `allow_na` argument (@martaalcalde, #1724)
1417
#
@@ -538,12 +541,20 @@ check_character <- function(
538541
check_logical <- function(
539542
x,
540543
...,
544+
allow_na = TRUE,
541545
allow_null = FALSE,
542546
arg = caller_arg(x),
543547
call = caller_env()
544548
) {
545549
if (!missing(x)) {
546550
if (is_logical(x)) {
551+
if (!allow_na && any(is.na(x))) {
552+
abort(
553+
sprintf("`%s` can't contain NA values.", arg),
554+
arg = arg,
555+
call = call
556+
)
557+
}
547558
return(invisible(NULL))
548559
}
549560
if (allow_null && is_null(x)) {

0 commit comments

Comments
 (0)