Skip to content

Commit

Permalink
Merge pull request #4 from edalfon/f-assert-on-multiple-conditions
Browse files Browse the repository at this point in the history
F assert on multiple conditions
  • Loading branch information
edalfon authored Jun 20, 2024
2 parents 8042a60 + 22b018f commit 5b36413
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 2 additions & 1 deletion R/assert.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 ",
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-assert.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down

0 comments on commit 5b36413

Please sign in to comment.