Skip to contents

Check a logical test

Usage

check_logical(
  dataset,
  uuid_column = "uuid",
  information_to_add = NULL,
  check_id = "logical_xx",
  check_to_perform,
  columns_to_clean = NULL,
  description
)

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)

check_id

name of the check to perform

check_to_perform

test to perform as R code (in text format)

columns_to_clean

variables to be put in the log. if not provided, it will try to detect variables

description

description of the check performed

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(),
  today = rep("2023-01-01", 10),
  location = rep(c("villageA", "villageB"), 5),
  distance_to_market = c(rep("less_30", 5), rep("more_30", 5)),
  access_to_market = c(rep("yes", 4), rep("no", 6)),
  number_children_05 = c(rep(c(0, 1), 4), 5, 6) )
 
check_logical(test_data,
  uuid_column = "uuid",
  check_id = "my_test",
  check_to_perform = "distance_to_market == \"less_30\" & access_to_market == \"no\"",
  columns_to_clean = "distance_to_market, access_to_market",
  description = "distance to market less than 30 and no access") |>
  knitr::kable()  
#> 
#> 
#> |uuid |today      |location |distance_to_market |access_to_market | number_children_05|my_test |
#> |:----|:----------|:--------|:------------------|:----------------|------------------:|:-------|
#> |1    |2023-01-01 |villageA |less_30            |yes              |                  0|FALSE   |
#> |2    |2023-01-01 |villageB |less_30            |yes              |                  1|FALSE   |
#> |3    |2023-01-01 |villageA |less_30            |yes              |                  0|FALSE   |
#> |4    |2023-01-01 |villageB |less_30            |yes              |                  1|FALSE   |
#> |5    |2023-01-01 |villageA |less_30            |no               |                  0|TRUE    |
#> |6    |2023-01-01 |villageB |more_30            |no               |                  1|FALSE   |
#> |7    |2023-01-01 |villageA |more_30            |no               |                  0|FALSE   |
#> |8    |2023-01-01 |villageB |more_30            |no               |                  1|FALSE   |
#> |9    |2023-01-01 |villageA |more_30            |no               |                  5|FALSE   |
#> |10   |2023-01-01 |villageB |more_30            |no               |                  6|FALSE   |
#> 
#> |uuid |question           |old_value |issue                                         |check_id |check_binding |
#> |:----|:------------------|:---------|:---------------------------------------------|:--------|:-------------|
#> |5    |distance_to_market |less_30   |distance to market less than 30 and no access |my_test  |my_test ~/~ 5 |
#> |5    |access_to_market   |no        |distance to market less than 30 and no access |my_test  |my_test ~/~ 5 |
 
check_logical(test_data,
  uuid_column = "uuid",
  information_to_add = c("today", "location"),
  check_to_perform = "distance_to_market == \"less_30\" & access_to_market == \"no\"",
  columns_to_clean = "distance_to_market, access_to_market",
  description = "distance to market less than 30 and no access")|>
  knitr::kable()  
#> 
#> 
#> |uuid |today      |location |distance_to_market |access_to_market | number_children_05|logical_xx |
#> |:----|:----------|:--------|:------------------|:----------------|------------------:|:----------|
#> |1    |2023-01-01 |villageA |less_30            |yes              |                  0|FALSE      |
#> |2    |2023-01-01 |villageB |less_30            |yes              |                  1|FALSE      |
#> |3    |2023-01-01 |villageA |less_30            |yes              |                  0|FALSE      |
#> |4    |2023-01-01 |villageB |less_30            |yes              |                  1|FALSE      |
#> |5    |2023-01-01 |villageA |less_30            |no               |                  0|TRUE       |
#> |6    |2023-01-01 |villageB |more_30            |no               |                  1|FALSE      |
#> |7    |2023-01-01 |villageA |more_30            |no               |                  0|FALSE      |
#> |8    |2023-01-01 |villageB |more_30            |no               |                  1|FALSE      |
#> |9    |2023-01-01 |villageA |more_30            |no               |                  5|FALSE      |
#> |10   |2023-01-01 |villageB |more_30            |no               |                  6|FALSE      |
#> 
#> |uuid |today      |location |question           |old_value |issue                                         |check_id   |check_binding    |
#> |:----|:----------|:--------|:------------------|:---------|:---------------------------------------------|:----------|:----------------|
#> |5    |2023-01-01 |villageA |distance_to_market |less_30   |distance to market less than 30 and no access |logical_xx |logical_xx ~/~ 5 |
#> |5    |2023-01-01 |villageA |access_to_market   |no        |distance to market less than 30 and no access |logical_xx |logical_xx ~/~ 5 |