Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .Rhistory
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
identical(x, x_s)
devtools::load_all(".")
expect_true(is_incrementing(1:5)) # TRUE
expect_true(is_incrementing(letters[1:5]))
expect_false(is_incrementing(c(4, 3, 0)))
expect_true(is_incrementing(1, NA, NA, 3))
expect_true(is_incrementing(1, 3, NA, NA))
Expand Down Expand Up @@ -510,3 +506,7 @@ devtools::check()
devtools::submit_cran()
renv::install("httr")
devtools::submit_cran()
devtools::check()
devtools::check()
devtools::submit_cran()
install.packages("schematic")
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: schematic
Title: Tidy Schema Validation for Data Frames
Version: 0.1.0
Version: 0.1.1
Authors@R: person("Will", "Hipson", email = "will.e.hipson@gmail.com", role = c("aut", "cre", "cph"), comment = c(ORCID = "0000-0002-3931-2189"))
Description: Validate data.frames against schemas to ensure that data matches expectations. Define schemas using 'tidyselect' and predicate functions for type consistency, nullability, and more. Schema failure messages can be tailored for non-technical users and are ideal for user-facing applications such as in 'shiny' or 'plumber'.
Maintainer: Will Hipson <will.e.hipson@gmail.com>
Expand Down
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# schematic 0.1.1

### Bug fixes

- Fixed issue where lots of column names in the message were being replaced with '...'.

- Fixed issue where checking on a column named `e` triggered error in `check_schema()`.

- Fixed issue where modifiers wouldn't work with custom predicates.

# schematic 0.1.0

### CRAN release
Expand Down
4 changes: 2 additions & 2 deletions R/check_schema.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ check_schema <- function(data, schema) {
cols <- tryCatch({
tidyselect::eval_select(selector, data) |>
names()
}, error = function(e) {
}, error = function(`___e`) { # avoid conflicts with columns named 'e'
still_exists <- tidyselect::eval_select(selector, data, strict = FALSE) |>
names()
check_cols <- clean_c_wrapper(
rlang::as_label(selector)
paste(deparse(selector), collapse = "")
) |>
strsplit(",\\s*")
check_cols <- check_cols[[1]]
Expand Down
2 changes: 2 additions & 0 deletions R/modifiers.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#' is_incrementing_null <- mod_nullable(is_incrementing)
#' is_incrementing_null(x) # TRUE
mod_nullable <- function(pred) {
pred <- rlang::as_function(pred)
function(x) {
if (all(is.na(x))) return(TRUE)
pred(x[!is.na(x)])
Expand All @@ -34,6 +35,7 @@ mod_nullable <- function(pred) {
#' is_incrementing_inf <- mod_infinitable(is_incrementing)
#' is_incrementing_inf(x) # TRUE
mod_infinitable <- function(pred) {
pred <- rlang::as_function(pred)
function(x) {
if (all(is.na(x))) return(TRUE)
pred(x[!is.infinite(x)])
Expand Down
29 changes: 29 additions & 0 deletions tests/testthat/test-check_schema.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,34 @@ test_that("rules with an error are handled", {
),
regexp = "Error in predicate"
)
})

test_that("lots of columns in message are still reported", {
sch <- schema(
c(departure_gate,
arrival_gate,
flight_date,
flight_id,
svc_type,
route,
ac_type,
status
) ~ is.character
)

expect_error(
check_schema(data.frame(), sch),
regexp = "Columns `departure_gate`"
)
})

test_that("lots of columns in message are still reported", {
sch <- schema(
e ~ is.character
)

expect_error(
check_schema(data.frame(a = 1), sch),
regexp = "Column `e`"
)
})
16 changes: 16 additions & 0 deletions tests/testthat/test-modifiers.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,19 @@ test_that("mod_infinitable", {
is_incrementing_inf <- mod_infinitable(is_incrementing)
expect_true(is_incrementing_inf(x))
})

test_that("mod_nullable works with custom function", {
sch <- schema(
c(a, b) ~ mod_nullable(~all(.x %in% c("a", "b", "c")))
)

expect_no_error({
check_schema(
data.frame(
a = c(NA, "a", "c"),
b = c("a", "b", "c")
),
sch
)
})
})