From fba7db192ca045de7d978ac70f1ce7464f68bc94 Mon Sep 17 00:00:00 2001 From: LucieContamin Date: Fri, 9 May 2025 15:38:01 -0400 Subject: [PATCH 1/3] add parameter --- R/imports-hubValidations.R | 13 +++++++++++-- man/store_msg_val.Rd | 5 ++++- tests/testthat/test_submission.R | 3 +++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/R/imports-hubValidations.R b/R/imports-hubValidations.R index bcc9906..f7ab69f 100644 --- a/R/imports-hubValidations.R +++ b/R/imports-hubValidations.R @@ -242,11 +242,13 @@ is_check_class <- function(x, #' Store validation output in a simple object #' #' @param msg validation output +#' @param rm_valid_check Boolean, remove valid check and `spl_non_compound` +#' output, by default FALSE. #' #' @importFrom dplyr case_when #' @importFrom purrr map_chr #' @export -store_msg_val <- function(msg) { +store_msg_val <- function(msg, rm_valid_check = FALSE) { txt <- paste( dplyr::case_when(is_check_class(msg, "check_success") ~ "\U002705", is_check_class(msg, "check_failure") ~ "\U002757", @@ -257,7 +259,14 @@ store_msg_val <- function(msg) { TRUE ~ "*"), paste0("[", names(msg), "]"), purrr::map_chr(msg, "message"), - sep = ": ", collapse = "\n" + sep = ": " ) + if (rm_valid_check) + txt <- purrr::discard(txt, ~grepl("\U002705|spl_non_compound", .x)) + if (length(txt) > 0 ) { + txt <- paste(txt, collapse = "\n") + } else { + txt <- "No issue reported" + } txt } diff --git a/man/store_msg_val.Rd b/man/store_msg_val.Rd index 998bc4f..7750445 100644 --- a/man/store_msg_val.Rd +++ b/man/store_msg_val.Rd @@ -4,10 +4,13 @@ \alias{store_msg_val} \title{Store validation output in a simple object} \usage{ -store_msg_val(msg) +store_msg_val(msg, rm_valid_check = FALSE) } \arguments{ \item{msg}{validation output} + +\item{rm_valid_check}{Boolean, remove valid check and \code{spl_non_compound} +output, by default FALSE.} } \description{ Store validation output in a simple object diff --git a/tests/testthat/test_submission.R b/tests/testthat/test_submission.R index c70345d..0310b67 100644 --- a/tests/testthat/test_submission.R +++ b/tests/testthat/test_submission.R @@ -102,6 +102,9 @@ test_that("Test validation process", { expect_contains(attr(check$req_vals, "class"), c("error", "check_error")) msg <- store_msg_val(check) expect_true(grepl("\U001F6AB.*\U002705", msg)) + msg2 <- store_msg_val(check, rm_valid_check = TRUE) + expect_true(nchar(msg) > nchar(msg2)) + expect_false(grepl("\U002705", msg2)) ## Additional data df <- rbind(df0, From e742161768358695ad9a7a54786c5912a7c00cd8 Mon Sep 17 00:00:00 2001 From: LucieContamin Date: Fri, 9 May 2025 15:39:39 -0400 Subject: [PATCH 2/3] update NEWS --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index 5f918d9..9aa0068 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,8 @@ output in a character vector with a slightly different format (#39) - add `ignore_val_err` parameter in the `validate_submission()` function to ignore stopping the validation if any `[valid_vals]` error (#40) +- add parameter `store_msg_val()` function to remove valid check (and non + compound id check) on output of the function (#44) # SMHvalidation 1.0.0 From 019f59013b1e4d3e83ca0a06076f109f05551c39 Mon Sep 17 00:00:00 2001 From: LucieContamin Date: Fri, 9 May 2025 15:46:17 -0400 Subject: [PATCH 3/3] fix lint --- R/imports-hubValidations.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/imports-hubValidations.R b/R/imports-hubValidations.R index f7ab69f..7e85c8f 100644 --- a/R/imports-hubValidations.R +++ b/R/imports-hubValidations.R @@ -263,7 +263,7 @@ store_msg_val <- function(msg, rm_valid_check = FALSE) { ) if (rm_valid_check) txt <- purrr::discard(txt, ~grepl("\U002705|spl_non_compound", .x)) - if (length(txt) > 0 ) { + if (length(txt) > 0) { txt <- paste(txt, collapse = "\n") } else { txt <- "No issue reported"