Skip to content

Commit

Permalink
swap out .data for NULLs
Browse files Browse the repository at this point in the history
  • Loading branch information
wibeasley committed Jul 24, 2023
1 parent b4cf836 commit 1820a8d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 27 deletions.
39 changes: 22 additions & 17 deletions R/execute-checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ execute_checks <- function(ds, checks) {

#' @importFrom rlang .data
execute_smells <- function(ds, checks) {
active <- baseline_date <- check_name <- data_collector <- error_message <- pass <- NULL
priority <- record_id <- redcap_instrument <- results <- violation_count <- NULL

checkmate::assert_data_frame(ds)
checkmate::assert_class(checks, "trawler_checks_definition")
checkmate::assert_data_frame(checks$smells)
Expand Down Expand Up @@ -86,8 +89,8 @@ execute_smells <- function(ds, checks) {
ds_smell_result <-
ds_smell_result |>
dplyr::select(
.data$check_name,
.data$pass,
check_name,
pass,
tidyselect::everything()
)

Expand All @@ -107,6 +110,8 @@ execute_smells <- function(ds, checks) {

#' @importFrom rlang .data
execute_rules <- function(ds, checks) {
baseline_date <- check_name <- data_collector <- error_message <- priority <- NULL
record_id <- redcap_instrument <- results <- violation_count <- NULL
checkmate::assert_data_frame(ds)
checkmate::assert_class(checks, "trawler_checks_definition")
checkmate::assert_data_frame(checks$rules)
Expand Down Expand Up @@ -156,7 +161,7 @@ execute_rules <- function(ds, checks) {
priority = checks$rules$priority[i],
redcap_instrument = checks$rules$redcap_instrument[i]
) |>
dplyr::select(.data$check_name, .data$record_id, .data$data_collector, .data$error_message, .data$priority, .data$redcap_instrument, .data$baseline_date)
dplyr::select(check_name, record_id, data_collector, error_message, priority, redcap_instrument, baseline_date)
}
rm(f, index, violations, ds_violation_single)
} # End for loop
Expand All @@ -165,28 +170,28 @@ execute_rules <- function(ds, checks) {
ds_rule_violation_list |>
dplyr::bind_rows() |>
dplyr::select(
.data$check_name,
.data$record_id,
.data$data_collector,
.data$baseline_date,
.data$redcap_instrument,
check_name,
record_id,
data_collector,
baseline_date,
redcap_instrument,
) |>
dplyr::mutate(
record_id_linked = sprintf(
checks$redcap_record_link,
checks$redcap_version, checks$redcap_project_id, checks$redcap_default_arm, .data$record_id, .data$redcap_instrument, .data$record_id
checks$redcap_version, checks$redcap_project_id, checks$redcap_default_arm, record_id, redcap_instrument, record_id
),
) |>
dplyr::select(
-.data$redcap_instrument
-redcap_instrument
) |>
dplyr::arrange(.data$check_name, .data$record_id) |>
dplyr::group_by(.data$check_name) |>
dplyr::arrange(check_name, record_id) |>
dplyr::group_by(check_name) |>
tidyr::nest(
results = -.data$check_name
results = -check_name
) |>
dplyr::mutate(
violation_count = purrr::map_int(.data$results, nrow)
violation_count = purrr::map_int(results, nrow)
)

rule_status <-
Expand All @@ -201,11 +206,11 @@ execute_rules <- function(ds, checks) {
checks$rules |>
dplyr::left_join(ds_rule_results, by = "check_name") |>
dplyr::mutate(
violation_count = dplyr::coalesce(.data$violation_count, 0L),
violation_count = dplyr::coalesce(violation_count, 0L),
) |>
dplyr::select(
.data$check_name,
.data$violation_count,
check_name,
violation_count,
tidyselect::everything(),
)

Expand Down
26 changes: 16 additions & 10 deletions R/load-checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ load_misc <- function(checks) {

#' @importFrom rlang .data
load_smells <- function(checks) {
active <- baseline_date <- bound_lower <- bound_upper <- bounds_template <- NULL
check_name <- data_collector <- error_message <- pass <- priority <- record_id <- NULL
redcap_instrument <- results <- violation_count <- NULL

ds_smell_all <-
checks$smells |>
purrr::map_df(tibble::as_tibble) |>
Expand All @@ -94,16 +98,16 @@ load_smells <- function(checks) {

smells <-
ds_smell_all |>
dplyr::filter(.data$active) |>
dplyr::filter(active) |>
dplyr::select(
-.data$active
-active
)

smells_inactive <-
ds_smell_all |>
dplyr::filter(!.data$active) |>
dplyr::filter(!active) |>
dplyr::select(
-.data$active
-active
)

# The smell columns (in the yaml checks file) should be correct.
Expand All @@ -120,7 +124,7 @@ load_smells <- function(checks) {
smells <-
smells |>
dplyr::mutate(
boundaries = sprintf(.data$bounds_template, .data$bound_lower, .data$bound_upper),
boundaries = sprintf(bounds_template, bound_lower, bound_upper),
)

# table(smells$check_name)
Expand Down Expand Up @@ -185,7 +189,9 @@ convert_equation <- function(equation, check_name) {

#' @importFrom rlang .data
load_rules <- function(checks) {
# https://stackoverflow.com/questions/47242697/denormalize-coerce-list-with-nested-vectors-to-data-frame-in-r
active <- baseline_date <- check_name <- data_collector <- error_message <- priority <- NULL
record_id <- redcap_instrument <- results <- violation_count <- NULL
# https://stackoverflow.com/questions/47242697/denormalize-coerce-list-with-nested-vectors-to-data-frame-in-r
ds_rule_all <-
checks$rules |>
purrr::map_df(tibble::as_tibble) |>
Expand All @@ -194,17 +200,17 @@ load_rules <- function(checks) {

rules <-
ds_rule_all |>
dplyr::filter(.data$active) |>
dplyr::filter(active) |>
dplyr::select(
-.data$active
-active
)

rules_inactive <-
checks$rules |>
purrr::map_df(tibble::as_tibble) |>
dplyr::filter(!.data$active) |>
dplyr::filter(!active) |>
dplyr::select(
-.data$active
-active
)

# The rule columns (in the yaml checks file) should be correct.
Expand Down

0 comments on commit 1820a8d

Please sign in to comment.