Last active
August 29, 2015 14:26
-
-
Save dholstius/793bfaefe55b79e28f63 to your computer and use it in GitHub Desktop.
Using `ensurer` to QA elements of a `data.frame`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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