Check several logical test
check_logical_with_list.Rd
This is a wrapper around check_logical to allow several checks to be performed.
Usage
check_logical_with_list(
dataset,
uuid_column = "uuid",
information_to_add = NULL,
list_of_check,
check_id_column,
check_to_perform_column,
columns_to_clean_column = NULL,
description_column,
bind_checks = TRUE
)
Arguments
- dataset
dataset to be check as a dataframe or a list with the dataframe stored as "checked_dataset"
- uuid_column
uuid column in the dataset. Default is "uuid".
- information_to_add
string vector optional, if to add some information to the log (today, vilagge)
- list_of_check
a dataframe with the checks to perform
- check_id_column
the column name with the names of each test.
- check_to_perform_column
the column name with the checks to perform as R code (in text format)
- columns_to_clean_column
the column name with the variables to be put in the log.
- description_column
the column name with the description
- bind_checks
default is TRUE, to bind the checks into 1 log.
Value
return a list with the dataset checked stored as checked_dataset, it will have all a column added with the check_id and a dataframe with the logical check log.
Examples
test_data <- data.frame(
uuid = c(1:10) %>% as.character(),
distance_to_market = rep(c("less_30", "more_30"), 5),
access_to_market = c(rep("yes", 4), rep("no", 6)),
number_children_05 = c(rep(c(0, 1), 4), 5, 6),
number_children_618 = c(rep(c(0, 1), 4), 5, 6)
)
check_list <- data.frame(
name = c("logical_xx", "logical_yy", "logical_zz"),
check = c(
"distance_to_market == \"less_30\" & access_to_market == \"no\"",
"number_children_05 > 3",
"rowSums(dplyr::across(starts_with(\"number\")), na.rm = T) > 9"
),
description = c(
"distance to market less than 30 and no access",
"number of children under 5 seems high",
"number of children very high"
),
columns_to_clean = c(
"distance_to_market, access_to_market",
"number_children_05",
""
)
)
check_logical_with_list(test_data,
uuid_column = "uuid",
list_of_check = check_list,
check_id_column = "name",
check_to_perform_column = "check",
columns_to_clean_column = "columns_to_clean",
description_column = "description") |>
knitr::kable()
#> Warning: columns_to_clean not shared, results may not be accurate
#>
#>
#> |uuid |distance_to_market |access_to_market | number_children_05| number_children_618|logical_xx |logical_yy |logical_zz |
#> |:----|:------------------|:----------------|------------------:|-------------------:|:----------|:----------|:----------|
#> |1 |less_30 |yes | 0| 0|FALSE |FALSE |FALSE |
#> |2 |more_30 |yes | 1| 1|FALSE |FALSE |FALSE |
#> |3 |less_30 |yes | 0| 0|FALSE |FALSE |FALSE |
#> |4 |more_30 |yes | 1| 1|FALSE |FALSE |FALSE |
#> |5 |less_30 |no | 0| 0|TRUE |FALSE |FALSE |
#> |6 |more_30 |no | 1| 1|FALSE |FALSE |FALSE |
#> |7 |less_30 |no | 0| 0|TRUE |FALSE |FALSE |
#> |8 |more_30 |no | 1| 1|FALSE |FALSE |FALSE |
#> |9 |less_30 |no | 5| 5|TRUE |TRUE |TRUE |
#> |10 |more_30 |no | 6| 6|FALSE |TRUE |TRUE |
#>
#> |uuid |question |old_value |issue |check_id |check_binding |
#> |:----|:------------------|:-------------------------------------|:---------------------------------------------|:----------|:-----------------|
#> |5 |distance_to_market |less_30 |distance to market less than 30 and no access |logical_xx |logical_xx ~/~ 5 |
#> |5 |access_to_market |no |distance to market less than 30 and no access |logical_xx |logical_xx ~/~ 5 |
#> |7 |distance_to_market |less_30 |distance to market less than 30 and no access |logical_xx |logical_xx ~/~ 7 |
#> |7 |access_to_market |no |distance to market less than 30 and no access |logical_xx |logical_xx ~/~ 7 |
#> |9 |distance_to_market |less_30 |distance to market less than 30 and no access |logical_xx |logical_xx ~/~ 9 |
#> |9 |access_to_market |no |distance to market less than 30 and no access |logical_xx |logical_xx ~/~ 9 |
#> |9 |number_children_05 |5 |number of children under 5 seems high |logical_yy |logical_yy ~/~ 9 |
#> |10 |number_children_05 |6 |number of children under 5 seems high |logical_yy |logical_yy ~/~ 10 |
#> |9 |unable to identify |please check this uuid for this check |number of children very high |logical_zz |logical_zz ~/~ 9 |
#> |10 |unable to identify |please check this uuid for this check |number of children very high |logical_zz |logical_zz ~/~ 10 |