Skip to content

Instantly share code, notes, and snippets.

@TransGirlCodes
Created August 13, 2023 17:30
Show Gist options
  • Save TransGirlCodes/d86d1a233a4575b3210a1f99a7467475 to your computer and use it in GitHub Desktop.
Save TransGirlCodes/d86d1a233a4575b3210a1f99a7467475 to your computer and use it in GitHub Desktop.
Testing use of validate_if inside of a box
box::use(./validate_if_box[...], data.table[...], data.validator[...])
test_tbl <- data.table(a = 1:5, b = 6:10)
test_schema <- data.table(name = c("a", "b"), class = c("numeric", "numeric"))
validate_columns_exist(validate(test_tbl), test_schema)
box::use(data.table[...], data.validator[...], assertr[...])
#' @export
validate_columns_exist <- function (data, schema) {
validate_if(
data,
# Things only work if I change this to assertr::has_all_names(!!!schema$name), defying the point of box.
has_all_names(!!!schema$name),
description = "Required columns exist"
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment