Skip to content

Instantly share code, notes, and snippets.

@dholstius
Last active August 29, 2015 14:26
Show Gist options
  • Save dholstius/793bfaefe55b79e28f63 to your computer and use it in GitHub Desktop.
Save dholstius/793bfaefe55b79e28f63 to your computer and use it in GitHub Desktop.
Using `ensurer` to QA elements of a `data.frame`
library(ensurer)
ensure_none_missing <- ensures_that(!any(is.na(.)) ~ "There are missing values")
ensure_all_positive <- ensures_that(all(int(.)) > 0 ~ "Not all values are positive", +ensure_none_missing)
# Everything works as expected with a simple vector
x <- 1:4
x %>% ensure_all_positive
# Now let's try testing element(s) of a data.frame
test_data <- data.frame(foo = x, bar = rep(-Inf, length(x)))
test_data %>%
ensure(all(.$foo > 0)) %>% # passes silently, as expected
ensure_all_positive(.$foo) # FAILS with "unused argument (.$foo)" ... why?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment