Checks that all elements from the specified columns are in a certain range

sc_cols_bounded(object, cols, rule = "(-Inf, Inf)", ...)

Arguments

object

table with a columns specified by cols

cols

vector of characters of columns that are checked against the specified range

rule

check as two numbers separated by a comma, enclosed by square brackets (endpoint included) or parentheses (endpoint excluded). For example, “[0, 3)” results in all(x >= 0 & x < 3). The lower and upper bound may be omitted which is the equivalent of a negative or positive infinite bound, respectively. By definition [0,] contains Inf, while [0,) does not. The same holds for the left (lower) boundary and -Inf. This explanation was copied from checkmate::qtest. That function is also the backbone of the this function.

...

further parameters that are passed to add_sanity_check.

Value

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

Examples

dummy_call <- function(x) { sc_cols_bounded(object = iris, cols = c("Sepal.Length", "Petal.Length"), rule = "[1, 7.9)") } dummy_call(x = d) get_sanity_checks()
#> description additional_desc data_name #> 1: bmi above 15 - x #> 2: bmi below 30 - #> 3: bmi above 15 - #> 4: - Elements in 'type' should contain only 'b', 'c', 'd'. d #> 5: - Elements in 'type' should contain only 'b', 'c', 'd'. d #> 6: - Elements in 'Sepal.Length' should be in [1, 7.9). iris #> 7: - Elements in 'Petal.Length' should be in [1, 7.9). iris #> n n_fail n_na counter_meas #> 1: 4 1 0 none #> 2: 4 1 0 none #> 3: 4 1 0 - #> 4: 4 1 0 - #> 5: 4 1 0 - #> 6: 150 1 0 - #> 7: 150 0 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)) #> 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)