Skip to content
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions R/standalone-types-check.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# ---
# repo: r-lib/rlang
# file: standalone-types-check.R
# last-updated: 2023-03-13
# last-updated: 2024-07-14
# license: https://unlicense.org
# dependencies: standalone-obj-type.R
# imports: rlang (>= 1.1.0)
# ---
#
# ## Changelog
# 2024-07-14:
# - `check_character()` gains `min_length` to allow prohibiting `character(0)` (@olivroy)
#
# 2023-03-13:
# - Improved error messages of number checkers (@teunbrand)
Expand Down Expand Up @@ -460,20 +462,26 @@ check_formula <- function(x,
check_character <- function(x,
...,
allow_null = FALSE,
min_length = 0,
arg = caller_arg(x),
call = caller_env()) {
if (!missing(x)) {
if (is_character(x)) {
if (is_character(x) && (length(x) >= min_length)) {
return(invisible(NULL))
}
if (allow_null && is_null(x)) {
return(invisible(NULL))
}
}

what <- "a character vector"
if (min_length > 1) {
what <- paste0(what, "of length greater or equal to", min_length)
}

stop_input_type(
x,
"a character vector",
what,
...,
allow_na = FALSE,
allow_null = allow_null,
Expand Down