diff --git a/DESCRIPTION b/DESCRIPTION index 6ff8f7f..532d61f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: efun Title: Miscellaneous Functions by E -Version: 0.3.4 +Version: 0.3.5 Authors@R: person(given = "Eduardo", family = "Alfonso-Sierra", diff --git a/R/assert.R b/R/assert.R index 5339728..a600efd 100644 --- a/R/assert.R +++ b/R/assert.R @@ -37,7 +37,8 @@ assert <- function(.data, ..., msg = "Assertion does not hold", na.rm = TRUE) { return(.data) } else { fail_msg <- purrr::imap(conds_eval, \(x, idx) { - n_fail <- sum(!x) + n_fail <- sum(!x, na.rm = na.rm) + if (n_fail > 0) { paste0( "\t`", idx, "` is false ", diff --git a/tests/testthat/test-assert.R b/tests/testthat/test-assert.R index 1b97f57..77f3a21 100644 --- a/tests/testthat/test-assert.R +++ b/tests/testthat/test-assert.R @@ -17,6 +17,12 @@ test_that("assert() does not fail testing data with NAs", { dplyr::mutate(mpg = dplyr::na_if(mpg, 15)) |> assert(mpg > 10) ) + expect_error( + object = mtcars |> + dplyr::mutate(mpg = dplyr::na_if(mpg, 15)) |> + assert(mpg > 10, !is.na(mpg)), + regexp = "Assertion does not hold" + ) }) test_that("assert() can handle multiple conditions", {