Skip to content

Commit

Permalink
pulling first function from validator-1
Browse files Browse the repository at this point in the history
ref #2
  • Loading branch information
wibeasley committed Dec 19, 2021
1 parent 947e10a commit a0ab635
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 4 deletions.
9 changes: 5 additions & 4 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
^trawler\.Rproj$
^\.Rproj\.user$
^LICENSE\.md$
^README\.Rmd$
^cran-comments\.md$
^\.github$

^codecov\.yml$
^cran-comments\.md$
^LICENSE\.md$
^README\.Rmd$
^trawler\.Rproj$
14 changes: 14 additions & 0 deletions .github/inst/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
default:
project_id: 1612 # This is located in data-public/metadata/validation-rules.yml also

path_derived_pt_event_csv: "data-public/derived/pt-event.csv"
path_derived_pt_event_rds: "data-public/derived/pt-event.rds"

path_derived_smell_summary_csv: "data-public/derived/summary-smell.csv"
path_derived_smell_summary_rds: "data-public/derived/summary-smell.rds"
path_derived_rule_summary_csv: "data-public/derived/summary-rule.csv"
path_derived_rule_summary_rds: "data-public/derived/summary-rule.rds"
path_derived_rule_violation_csv: "data-public/derived/violation-rule.csv"
path_derived_rule_violation_rds: "data-public/derived/violation-rule.rds"

path_log_flow: !expr strftime(Sys.time(), "data-unshared/log/%Y/%Y-%m/flow-%Y-%m-%d--%H-%M-%S.log")
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Generated by roxygen2: do not edit by hand

export(load_checks)
importFrom(rlang,.data)
66 changes: 66 additions & 0 deletions R/load-checks.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#' @title Load and parse checks in a yaml file, and return a list
#' of useful objects.
#' @param path_checks The file path to the yaml file specifying the smells
#' and rules.
#' @export
load_checks <- function (path_checks) {
checkmate::assert_file_exists(path_checks, extension = c("yml", "yaml"))

checks <- config::get(file = path_checks)

smells <- load_smells(checks)

list(
ds_smell = smells$ds_smell,
ds_smell_inactive = smells$ds_smell_inactive
)
}

#' @importFrom rlang .data
load_smells <- function (checks) {

ds_smell <-
checks$smells |>
purrr::map_df(tibble::as_tibble) |>
dplyr::filter(.data$smell_active) |>
dplyr::mutate(
debug = dplyr::coalesce(debug, FALSE),
)

ds_smell_inactive <-
checks$smells |>
purrr::map_df(tibble::as_tibble) |>
dplyr::filter(!.data$smell_active)

testit::assert("The count of distinct rule columns (in the yaml checks file) should be 10.", ncol(ds_smell) == 10L)
testit::assert( # dput(colnames(ds_smell))
"The smell columns (in the yaml checks file) should be correct.",
colnames(ds_smell) == c("check_name", "description", "priority", "smell_active", "debug", "bound_lower", "bound_upper", "bounds_template", "value_template", "equation")
)

ds_smell <-
ds_smell |>
dplyr::mutate(
boundaries = sprintf(.data$bounds_template, .data$bound_lower, .data$bound_upper),
)
# table(ds_smell$check_name)
# OuhscMunge::verify_value_headstart(ds_smell)
checkmate::assert_character(ds_smell$check_name , any.missing=F , pattern="^.{4,99}$" , unique=T)
checkmate::assert_character(ds_smell$description , any.missing=F , pattern="^.{4,255}$" , unique=T)
checkmate::assert_integer( ds_smell$priority , any.missing=F , lower=1, upper=5 )
checkmate::assert_logical( ds_smell$smell_active , any.missing=F )
checkmate::assert_logical( ds_smell$debug , any.missing=F )
checkmate::assert_numeric( ds_smell$bound_lower , any.missing=F )
checkmate::assert_numeric( ds_smell$bound_upper , any.missing=F )
checkmate::assert_character(ds_smell$bounds_template , any.missing=F , pattern="^.{2,255}$" )
checkmate::assert_character(ds_smell$value_template , any.missing=F , pattern="^.{2,255}$" )
checkmate::assert_character(ds_smell$equation , any.missing=F , pattern="^.{5,}$" , unique=T)
checkmate::assert_character(ds_smell$boundaries , any.missing=F , pattern="^.{6,}$" )

list(
ds_smell = ds_smell,
ds_smell_inactive = ds_smell_inactive
)
}

# load_checks("data-public/metadata/validation-rules.yml")
17 changes: 17 additions & 0 deletions man/load_checks.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a0ab635

Please sign in to comment.