OUHSC Statistical Computing User Group
Will Beasley1, Geneva Marshall1, Thomas Wilson1,
Som Bohora2, & Maleeha Shahid2.
validation_check <- function(
name, error_message, priority, passing_test
) {
# S3 object to check
l <- list()
class(l) <- "check"
l$name <- name
l$error_message <- error_message
l$priority <- priority
l$passing_test <- passing_test
return( l )
}
# Add to this list for new validators.
checks <- list(
validation_check(
name = "record_id_no_white_space",
error_message = "'record_id' contains white space.",
priority = 1L,
passing_test = function( d ) {
!grepl("\\s", d$record_id, perl=T)
}
),
validation_check(
name = "interview_started_set",
error_message = "`interview_started` can't be missing.",
priority = 2L,
passing_test = function( d ) {
!is.na(d$interview_started)
}
),
...
)
for( check in checks ) {
index <- length(ds_violation_list) + 1L
violations <- !check$passing_test(ds_interview)
ds_violation <- ds_interview %>%
dplyr::filter(violations)
if( nrow(ds_violation) > 0L ) {
ds_violation_list[[index]] <- extract_violation_info(ds_violation, check)
}
rm(violations, ds_violation)
}
DT::datatable(
data = ds_violation_pretty,
filter = "bottom",
caption = paste("Violations at", Sys.time()),
escape = FALSE,
options = list(pageLength = 30, dom = 'tip')
)
# ---- save-to-disk ----------------------------------
message("Saving list of violations to `", path_output, "`.")
readr::write_csv(ds_violation, path=path_output)