Retrieve validation results as a data.frame
Source:R/as-data-frame.R
as.data.frame.tbl_validation.Rd
Retrieve validation results as a data.frame
Usage
# S3 method for tbl_validation
as.data.frame(x, row.names = NULL, optional = FALSE, ...)
Arguments
- x
tbl_validation()
, result of aconfront()
oftbl
with a rule set.- row.names
ignored
- optional
ignored
- ...
ignored
Examples
# create a table in a database
income <- data.frame(id = letters[1:2], age=c(12,35), salary = c(1000,NA))
con <- dbplyr::src_memdb()
tbl_income <- dplyr::copy_to(con, income, overwrite=TRUE)
# Let's define a rule set and confront the table with it:
rules <- validator( is_adult = age >= 18
, has_income = salary > 0
, mean_age = mean(age,na.rm=TRUE) > 20
)
# and confront!
cf <- confront(tbl_income, rules, key = "id")
as.data.frame(cf)
#> id is_adult has_income mean_age
#> 1 a FALSE TRUE TRUE
#> 2 b TRUE NA TRUE
# and now with a sparse result:
cf <- confront(tbl_income, rules, key = "id", sparse=TRUE)
as.data.frame(cf)
#> id rule fail
#> 1 a is_adult TRUE
#> 2 b has_income NA