Checks that the combination of the specified columns is unique

sc_cols_unique(object, cols = names(object), ...)

Arguments

object

table with a columns specified by cols

cols

vector of characters which combination is checked to be unique

...

further parameters that are passed to add_sanity_check.

Value

see return object of add_sanity_check. Note that if a combination appears 3 times, then n_fail will increased by 3.

Examples

dummy_call <- function(x) { sc_cols_unique( object = x, cols = c("Species", "Sepal.Length", "Sepal.Width", "Petal.Length")) } dummy_call(x = iris)
#> $entry_sanity_table #> description #> 1: - #> additional_desc #> 1: The combination of 'Species', 'Sepal.Length', 'Sepal.Width', 'Petal.Length' is unique #> data_name n n_fail n_na counter_meas fail_vec_str #> 1: x 150 12 0 - dt$.n_col_cmb != 1 #> param_name #> 1: 'Species', 'Sepal.Length', 'Sepal.Width', 'Petal.Length' #> call example #> 1: dummy_call(x = iris) <data.table[3x6]> #> #> $fail_vec #> [1] TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE #> [13] TRUE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE #> [25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE #> [37] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE #> [49] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> [61] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> [73] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> [85] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> [97] FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE #> [109] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> [121] FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE TRUE FALSE FALSE FALSE #> [133] TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE #> [145] TRUE FALSE FALSE FALSE FALSE FALSE #> #> $fail #> [1] TRUE #>
#> 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 #> 17: - #> additional_desc #> 1: - #> 2: - #> 3: - #> 4: Elements in 'type' should contain only 'b', 'c', 'd'. #> 5: Elements in 'type' should contain only 'b', 'c', 'd'. #> 6: Elements in 'Sepal.Length' should be in [1, 7.9). #> 7: Elements in 'Petal.Length' should be in [1, 7.9). #> 8: Elements in 'a' should be in (0.2, Inf). #> 9: Elements in 'b' should be in (0.2, Inf). #> 10: Check that column 'Sepal.Length' does not contain NA #> 11: Check that column 'Sepal.Width' does not contain NA #> 12: Check that column 'Petal.Length' does not contain NA #> 13: Check that column 'Petal.Width' does not contain NA #> 14: Check that column 'Species' does not contain NA #> 15: Elements in 'a' should be in (0, Inf). #> 16: Elements in 'b' should be in (0, Inf). #> 17: The combination of 'Species', 'Sepal.Length', 'Sepal.Width', 'Petal.Length' is unique #> data_name n n_fail n_na counter_meas #> 1: x 4 1 0 none #> 2: 4 1 0 none #> 3: 4 1 0 - #> 4: d 4 1 0 - #> 5: d 4 1 0 - #> 6: iris 150 1 0 - #> 7: iris 150 0 0 - #> 8: d 4 3 0 - #> 9: d 4 0 0 - #> 10: iris 150 5 0 - #> 11: iris 150 0 0 - #> 12: iris 150 0 0 - #> 13: iris 150 0 0 - #> 14: iris 150 0 0 - #> 15: d 4 2 0 - #> 16: d 4 0 0 - #> 17: x 150 12 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)) #> 17: dt$.n_col_cmb != 1 #> param_name #> 1: bmi #> 2: - #> 3: - #> 4: type #> 5: type #> 6: Sepal.Length #> 7: Petal.Length #> 8: a #> 9: b #> 10: Sepal.Length #> 11: Sepal.Width #> 12: Petal.Length #> 13: Petal.Width #> 14: Species #> 15: a #> 16: b #> 17: 'Species', 'Sepal.Length', 'Sepal.Width', 'Petal.Length' #> call example #> 1: dummy_call(x = d) <data.frame[1x3]> #> 2: dummy_call(x = d) #> 3: eval(expr, envir, enclos) #> 4: eval(expr, envir, enclos) <data.frame[1x2]> #> 5: dummy_call(x = d) <data.frame[1x2]> #> 6: dummy_call(x = d) <data.frame[1x5]> #> 7: dummy_call(x = d) #> 8: dummy_call(x = d) <data.frame[3x2]> #> 9: dummy_call(x = d) #> 10: dummy_call(x = iris) <data.frame[3x5]> #> 11: dummy_call(x = iris) #> 12: dummy_call(x = iris) #> 13: dummy_call(x = iris) #> 14: dummy_call(x = iris) #> 15: dummy_call(x = d) <data.frame[2x2]> #> 16: dummy_call(x = d) #> 17: dummy_call(x = iris) <data.table[3x6]>
get_sanity_checks()[["example"]]
#> [[1]] #> person_id bmi age #> 3 3 -1 33 #> #> [[2]] #> NULL #> #> [[3]] #> NULL #> #> [[4]] #> type nmb #> 1 a 1 #> #> [[5]] #> type nmb #> 1 a 1 #> #> [[6]] #> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> 132 7.9 3.8 6.4 2 virginica #> #> [[7]] #> NULL #> #> [[8]] #> a b #> 1 0.0 1 #> 2 0.2 2 #> 4 Inf 4 #> #> [[9]] #> NULL #> #> [[10]] #> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> 1 NA 3.5 1.4 0.2 setosa #> 3 NA 3.2 1.3 0.2 setosa #> 5 NA 3.6 1.4 0.2 setosa #> #> [[11]] #> NULL #> #> [[12]] #> NULL #> #> [[13]] #> NULL #> #> [[14]] #> NULL #> #> [[15]] #> a b #> 1 0 1 #> 4 Inf 4 #> #> [[16]] #> NULL #> #> [[17]] #> Sepal.Length Sepal.Width Petal.Length Petal.Width Species .n_col_cmb #> 1: 5.1 3.5 1.4 0.2 setosa 2 #> 2: 4.9 3.1 1.5 0.1 setosa 2 #> 3: 4.8 3.0 1.4 0.1 setosa 2 #>