R/convenience.R
sc_cols_bounded_below.RdChecks that all elements from the given columns are above a certain number
sc_cols_bounded_below( object, cols, lower_bound, include_lower_bound = TRUE, ... )
| object | table with a columns specified by |
|---|---|
| cols | vector of characters of columns that are checked against the specified range |
| lower_bound | elements of the specified columns must be above this bound |
| include_lower_bound | if TRUE (default), elements are allowed to be
equal to the |
| ... | 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_bounded_below( object = d, cols = c("a", "b"), lower_bound = 0.2, include_lower_bound = FALSE, description = "Measurements are expected to be bounded from below") } dummy_call(x = d)#> $a #> $a$entry_sanity_table #> description #> 1: Measurements are expected to be bounded from below #> additional_desc data_name n n_fail n_na #> 1: Elements in 'a' should be in (0.2, Inf). d 4 3 0 #> counter_meas #> 1: - #> 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[3x2]> #> #> $a$fail_vec #> [1] TRUE TRUE FALSE TRUE #> #> $a$fail #> [1] TRUE #> #> #> $b #> $b$entry_sanity_table #> description #> 1: Measurements are expected to be bounded from below #> additional_desc data_name n n_fail n_na #> 1: Elements in 'b' should be in (0.2, Inf). d 4 0 0 #> counter_meas #> 1: - #> 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 #> 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 #> n_na counter_meas #> 1: 0 none #> 2: 0 none #> 3: 0 - #> 4: 0 - #> 5: 0 - #> 6: 0 - #> 7: 0 - #> 8: 0 - #> 9: 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)) #> 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)