R/rule_works_on_tbl.R

Defines functions rule_works_on_tbl

Documented in rule_works_on_tbl

#' tests for each rule if it can be executed on the database
#' 
#' tests for each rule if it can be executed on the database
#' @param tbl a `tbl` object with columns used in `x`
#' @param x a [validate::validator()] object
#' @return `logical` encoding which validation rules "work" on the database.
#' @importFrom utils head
rule_works_on_tbl <- function(tbl, x){
  res <- confront_tbl_sparse(head(tbl), x, union_all = FALSE, check_rules = FALSE)
  # TODO extract information on the error...
  sapply(res$query, function(qry){
    works <- FALSE
    try({
      dplyr::collect(head(qry))
      works <- TRUE
    }, silent = TRUE)
    works
  })
}

Try the validatedb package in your browser

Any scripts or data that you put into this service are public.

validatedb documentation built on Oct. 6, 2021, 5:17 p.m.