## ----include = FALSE---------------------------------------------------------- knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) ## ----------------------------------------------------------------------------- library(data.checker) df <- data.frame( age = c(10, 11, 13, 15, 22, 34, 80), sex = c("M", "F", "M", "F", "M", "F", "M") ) df ## ----------------------------------------------------------------------------- schema <- list( check_duplicates = FALSE, check_completeness = FALSE, columns = list( age = list(type = "integer", optional = FALSE), sex = list(type = "character", optional = FALSE) ) ) schema ## ----------------------------------------------------------------------------- validator <- data.checker::new_validator( data = df, schema = schema ) ## ----echo = FALSE------------------------------------------------------------- anonymise_validator <- function(validator_object){ validator_object[["log"]][[1]][["description"]] <- "Date: 2025-01-01\nsysname: Windows\nrelease: 10 x64\nversion: \nnodename: \nmachine: \nlogin: username\nuser: username\neffective_user: username\nudomain: \nR version : R version 4.5.1 (2025-06-13 ucrt)\ndata.checker version: 0.0.0.9000\n" return(validator_object) } validator <- anonymise_validator(validator) ## ----------------------------------------------------------------------------- print(validator) ## ----------------------------------------------------------------------------- check_results <- data.checker::check(validator) print(check_results) ## ----eval = FALSE------------------------------------------------------------- # data.checker::export(check_results, file = "example.html", format = "html") ## ----eval = FALSE------------------------------------------------------------- # data.checker::check_and_export(df, schema, file = "example.html", format = "html", hard_check = FALSE) ## ----------------------------------------------------------------------------- df <- data.frame( id = 1:10, age = c(10, 20, 30, 40, 50, 60, 70, 80, 90, 100), sex = c("M", "F", "M", "F", "M", "F", "M", "F", "M", "F"), country = factor( c("England", "England", "Wales", "Scotland", "Wales", "England", "Northern Ireland", "Wales", "Scotland", "Northern Ireland"), levels = c("England", "Scotland", "Wales", "Northern Ireland")), date = lubridate::ymd(c( "2021-01-01", "2021-02-01", "2021-02-01", "2021-03-01", "2021-03-01", "2021-03-01", "2021-04-01", "2021-04-01", "2021-04-01", "2021-05-01" )) ) data_check_results <- data.checker::new_validator(schema = "example_schema.yaml", data = df) |> data.checker::check() ## ----echo = FALSE------------------------------------------------------------- data_check_results <- anonymise_validator(data_check_results) ## ----------------------------------------------------------------------------- print(data_check_results) ## ----------------------------------------------------------------------------- df <- data.frame( id = 1:10, age = c(10, 20, 30, 40, 50, 60, 70, 80, 90, 100), sex = c("M", "F", "M", "F", "M", "F", "M", "F", "M", "F") ) schema <- list( check_duplicates = FALSE, check_completeness = FALSE, columns = list( id = list(type = "double", optional = FALSE), age = list(type = "double", optional = FALSE), sex = list(type = "character", optional = FALSE) ) ) data_check_results <- data.checker::new_validator(df, schema) |> data.checker::check() |> data.checker::add_check(description = "There are no males over 90 (tidy evaluation)", condition = !(sex == "M" & age > 90)) |> data.checker::add_check(description = "There are no males over 90 (standard evaluation)", condition = !(df$sex == "M" & df$age > 90)) ## ----------------------------------------------------------------------------- data_check_results <- anonymise_validator(data_check_results) ## ----------------------------------------------------------------------------- print(data_check_results) ## ----------------------------------------------------------------------------- df <- data.frame( age = c(10, 11, 13, 15, 22, 34, 80), sex = c("M", "F", "M", "F", "M", "F", "M") ) schema <- list( check_completeness = FALSE, check_duplicates = FALSE, columns = list( age = list(type = "integer", optional = FALSE), sex = list(type = "character", optional = FALSE) ) ) validator <- data.checker::new_validator(df, schema) validator <- data.checker::add_qa_entry( validator, description = "Example custom log entry", entry_type = "info" ) ## ----------------------------------------------------------------------------- validator <- anonymise_validator(validator) ## ----------------------------------------------------------------------------- print(validator)