R/convenience.R
sc_cols_positive.RdChecks that all elements from the specified columns are positive
sc_cols_positive(object, cols, zero_feasible = TRUE, ...)
| object | table with a columns specified by |
|---|---|
| cols | vector of characters of columns that are checked against the specified range |
| zero_feasible | if zero is in the range or not |
| ... | further parameters that are passed to add_sanity_check. |
list of logical vectors where TRUE indicates where the check failed. Every list entry represents one of the columns specified in cols. This might be helpful if one wants to apply a counter-measure.
d <- data.frame(a = c(0, 0.2, 3, Inf), b = c(1:4)) dummy_call <- function(x) { sc_cols_positive(d, cols = c("a", "b"), zero_feasible = FALSE, description = "Measurements are expected to be positive") } dummy_call(x = d)#> $a #> $a$entry_sanity_table #> description #> 1: Measurements are expected to be positive #> additional_desc data_name n n_fail n_na counter_meas #> 1: Elements in 'a' should be in (0, Inf). d 4 2 0 - #> fail_vec_str #> 1: sapply(object[[col]], function(x) !checkmate::qtest(x = x, rules = rule)) #> param_name call example #> 1: a dummy_call(x = d) <data.frame[2x2]> #> #> $a$fail_vec #> [1] TRUE FALSE FALSE TRUE #> #> $a$fail #> [1] TRUE #> #> #> $b #> $b$entry_sanity_table #> description #> 1: Measurements are expected to be positive #> additional_desc data_name n n_fail n_na counter_meas #> 1: Elements in 'b' should be in (0, Inf). d 4 0 0 - #> fail_vec_str #> 1: sapply(object[[col]], function(x) !checkmate::qtest(x = x, rules = rule)) #> param_name call #> 1: b dummy_call(x = d) #> #> $b$fail_vec #> [1] FALSE FALSE FALSE FALSE #> #> $b$fail #> [1] FALSE #> #>#> description #> 1: bmi above 15 #> 2: bmi below 30 #> 3: bmi above 15 #> 4: - #> 5: - #> 6: - #> 7: - #> 8: Measurements are expected to be bounded from below #> 9: Measurements are expected to be bounded from below #> 10: No NAs expected in iris #> 11: No NAs expected in iris #> 12: No NAs expected in iris #> 13: No NAs expected in iris #> 14: No NAs expected in iris #> 15: Measurements are expected to be positive #> 16: Measurements are expected to be positive #> additional_desc data_name n n_fail #> 1: - x 4 1 #> 2: - 4 1 #> 3: - 4 1 #> 4: Elements in 'type' should contain only 'b', 'c', 'd'. d 4 1 #> 5: Elements in 'type' should contain only 'b', 'c', 'd'. d 4 1 #> 6: Elements in 'Sepal.Length' should be in [1, 7.9). iris 150 1 #> 7: Elements in 'Petal.Length' should be in [1, 7.9). iris 150 0 #> 8: Elements in 'a' should be in (0.2, Inf). d 4 3 #> 9: Elements in 'b' should be in (0.2, Inf). d 4 0 #> 10: Check that column 'Sepal.Length' does not contain NA iris 150 5 #> 11: Check that column 'Sepal.Width' does not contain NA iris 150 0 #> 12: Check that column 'Petal.Length' does not contain NA iris 150 0 #> 13: Check that column 'Petal.Width' does not contain NA iris 150 0 #> 14: Check that column 'Species' does not contain NA iris 150 0 #> 15: Elements in 'a' should be in (0, Inf). d 4 2 #> 16: Elements in 'b' should be in (0, Inf). d 4 0 #> n_na counter_meas #> 1: 0 none #> 2: 0 none #> 3: 0 - #> 4: 0 - #> 5: 0 - #> 6: 0 - #> 7: 0 - #> 8: 0 - #> 9: 0 - #> 10: 0 - #> 11: 0 - #> 12: 0 - #> 13: 0 - #> 14: 0 - #> 15: 0 - #> 16: 0 - #> fail_vec_str #> 1: x$bmi < 15 #> 2: x$bmi > 30 #> 3: d$bmi < 15 #> 4: !(object[[col]] %in% feasible_elements) #> 5: !(object[[col]] %in% feasible_elements) #> 6: sapply(object[[col]], function(x) !checkmate::qtest(x = x, rules = rule)) #> 7: sapply(object[[col]], function(x) !checkmate::qtest(x = x, rules = rule)) #> 8: sapply(object[[col]], function(x) !checkmate::qtest(x = x, rules = rule)) #> 9: sapply(object[[col]], function(x) !checkmate::qtest(x = x, rules = rule)) #> 10: is.na(object[[col]]) #> 11: is.na(object[[col]]) #> 12: is.na(object[[col]]) #> 13: is.na(object[[col]]) #> 14: is.na(object[[col]]) #> 15: sapply(object[[col]], function(x) !checkmate::qtest(x = x, rules = rule)) #> 16: sapply(object[[col]], function(x) !checkmate::qtest(x = x, rules = rule)) #> param_name call example #> 1: bmi dummy_call(x = d) <data.frame[1x3]> #> 2: - dummy_call(x = d) #> 3: - eval(expr, envir, enclos) #> 4: type eval(expr, envir, enclos) <data.frame[1x2]> #> 5: type dummy_call(x = d) <data.frame[1x2]> #> 6: Sepal.Length dummy_call(x = d) <data.frame[1x5]> #> 7: Petal.Length dummy_call(x = d) #> 8: a dummy_call(x = d) <data.frame[3x2]> #> 9: b dummy_call(x = d) #> 10: Sepal.Length dummy_call(x = iris) <data.frame[3x5]> #> 11: Sepal.Width dummy_call(x = iris) #> 12: Petal.Length dummy_call(x = iris) #> 13: Petal.Width dummy_call(x = iris) #> 14: Species dummy_call(x = iris) #> 15: a dummy_call(x = d) <data.frame[2x2]> #> 16: b dummy_call(x = d)