Skip to content

Commit

Permalink
fix multiline read from yaml; do not crash on filtering where no fail…
Browse files Browse the repository at this point in the history
…s are present
  • Loading branch information
DavZim committed Jul 21, 2023
1 parent 9c1e244 commit 381becf
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: dataverifyr
Type: Package
Title: A Lightweight, Flexible, and Fast Data Validation Package that Can Handle All Sizes of Data
Version: 0.1.6
Version: 0.1.6.9001
Authors@R: c(
person(given = "David",
family = "Zimmermann-Kollenda",
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# dataverifyr 0.1.6

* allow multiline rules in yaml file
* fix bug where no fails in filter_fails would result in error
* Fix bug where multiline rules would break

* fix minor error in Readme
* `filter_fails()` allows the first argument to be a `ruleset` and not only a result of `check_data()`

Expand Down
2 changes: 2 additions & 0 deletions R/filters.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ filter_fails <- function(res, x, per_rule = FALSE) {
negated <- res$negate[fails]
allow_na <- res$allow_na[fails]

if (all(!fails)) return(x[0, ])

}

type <- detect_type(class(x))
Expand Down
1 change: 1 addition & 0 deletions R/im-export.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ read_rules <- function(file) {
}

res <- lapply(res, function(r) {
r$expr <- paste(r$expr, collapse = "\n")
class(r) <- "rule"
r
})
Expand Down
20 changes: 20 additions & 0 deletions tests/testthat/test-filters.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,23 @@ test_that("filters return values that are not matched by the rules", {
fails2 <- filter_fails(rules, data, per_rule = TRUE)
expect_equal(fails2, fails)
})

test_that("No fails do not crash", {
data <- mtcars

rules <- ruleset(
rule(mpg > 10 & mpg < 35),
rule(cyl != 5),
rule(vs %in% c(0, 1))
)

res <- check_data(data, rules)
rr <- filter_fails(res, data)
expect_equal(nrow(rr), 0)
expect_equal(names(rr), names(data))

# also works when ruleset is provided
rr2 <- filter_fails(rules, data)
expect_equal(nrow(rr2), 0)
expect_equal(names(rr2), names(data))
})

0 comments on commit 381becf

Please sign in to comment.