From 1f7ac867974463690198e1da7479de4b1bfac2e6 Mon Sep 17 00:00:00 2001 From: olivroy <52606734+olivroy@users.noreply.github.com> Date: Sun, 14 Jul 2024 11:00:28 -0400 Subject: [PATCH 1/5] Add `allow_zero` to `check_character()` --- R/standalone-types-check.R | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/R/standalone-types-check.R b/R/standalone-types-check.R index 90a889f1b..11fefba62 100644 --- a/R/standalone-types-check.R +++ b/R/standalone-types-check.R @@ -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 `allow_zero` to allow prohibiting `character(0)` (@olivroy) # # 2023-03-13: # - Improved error messages of number checkers (@teunbrand) @@ -460,10 +462,11 @@ check_formula <- function(x, check_character <- function(x, ..., allow_null = FALSE, + allow_zero = TRUE, arg = caller_arg(x), call = caller_env()) { if (!missing(x)) { - if (is_character(x)) { + if (is_character(x) && (allow_zero || length(x) > 0)) { return(invisible(NULL)) } if (allow_null && is_null(x)) { From a34d831934c3cffd285cd40bfd49d4f7ee373122 Mon Sep 17 00:00:00 2001 From: olivroy <52606734+olivroy@users.noreply.github.com> Date: Thu, 15 Aug 2024 19:15:07 -0400 Subject: [PATCH 2/5] Use min_length instead --- R/standalone-types-check.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/standalone-types-check.R b/R/standalone-types-check.R index 11fefba62..d6325c2e3 100644 --- a/R/standalone-types-check.R +++ b/R/standalone-types-check.R @@ -9,7 +9,7 @@ # # ## Changelog # 2024-07-14: -# - `check_character()` gains `allow_zero` to allow prohibiting `character(0)` (@olivroy) +# - `check_character()` gains `min_length` to allow prohibiting `character(0)` (@olivroy) # # 2023-03-13: # - Improved error messages of number checkers (@teunbrand) @@ -462,11 +462,11 @@ check_formula <- function(x, check_character <- function(x, ..., allow_null = FALSE, - allow_zero = TRUE, + min_length = 0, arg = caller_arg(x), call = caller_env()) { if (!missing(x)) { - if (is_character(x) && (allow_zero || length(x) > 0)) { + if (is_character(x) && (length(x) >= min_length)) { return(invisible(NULL)) } if (allow_null && is_null(x)) { From 2b180358dd584550d2f8e18d71aa639735c5b049 Mon Sep 17 00:00:00 2001 From: olivroy <52606734+olivroy@users.noreply.github.com> Date: Thu, 15 Aug 2024 19:16:18 -0400 Subject: [PATCH 3/5] Update standalone-types-check.R --- R/standalone-types-check.R | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/R/standalone-types-check.R b/R/standalone-types-check.R index d6325c2e3..7d9a44dc0 100644 --- a/R/standalone-types-check.R +++ b/R/standalone-types-check.R @@ -474,9 +474,14 @@ check_character <- function(x, } } + what <- "a character vector" + if (min_length > 0) { + 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, From 51f55da33204a19c00b5517291adf3d4456075e6 Mon Sep 17 00:00:00 2001 From: olivroy <52606734+olivroy@users.noreply.github.com> Date: Thu, 15 Aug 2024 19:24:06 -0400 Subject: [PATCH 4/5] Update R/standalone-types-check.R --- R/standalone-types-check.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/standalone-types-check.R b/R/standalone-types-check.R index 7d9a44dc0..ce1f5daeb 100644 --- a/R/standalone-types-check.R +++ b/R/standalone-types-check.R @@ -475,7 +475,7 @@ check_character <- function(x, } what <- "a character vector" - if (min_length > 0) { + if (min_length > 1) { what <- paste0(what, "of length greater or equal to", min_length) } From 8906c8b24472a279ca248a504cf021b30bf2288f Mon Sep 17 00:00:00 2001 From: olivroy <52606734+olivroy@users.noreply.github.com> Date: Sun, 18 Aug 2024 11:21:15 -0400 Subject: [PATCH 5/5] Update standalone-types-check.R --- R/standalone-types-check.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/standalone-types-check.R b/R/standalone-types-check.R index ce1f5daeb..336224ce7 100644 --- a/R/standalone-types-check.R +++ b/R/standalone-types-check.R @@ -476,7 +476,7 @@ check_character <- function(x, what <- "a character vector" if (min_length > 1) { - what <- paste0(what, "of length greater or equal to", min_length) + what <- paste(what, "of length greater or equal to", min_length) } stop_input_type(