Description Usage Arguments Details Value See Also Examples
Confront dbplyr::tbl_dbi()
objects with validate::validator()
rules, making it
possible to execute validator()
rules on database tables. Validation results
can be stored in the db or retrieved into R.
1 2 3 4 |
tbl |
|
x |
|
ref |
reference object (not working) |
key |
|
sparse |
|
compute |
|
... |
passed through to |
dat |
an object of class 'tbl_sql“. |
validatedb
builds upon dplyr
and dbplyr
, so it works on all databases
that have a dbplyr compatible database driver (DBI / odbc).
validatedb
translates validator
rules into dplyr
commands resulting in
a lazy query object. The result of a validation can be stored in the database
using compute
or retrieved into R with values
.
a tbl_validation()
object, containing the confrontation query and processing information.
Other validation:
tbl_validation-class
,
values,tbl_validation-method
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | # 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)
print(tbl_income)
# 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)
print(cf)
summary(cf)
# Values (i.e. validations on the table) can be retrieved like in `validate`
# with`type="matrix"` (simplify = TRUE)
values(cf, type = "matrix")
# But often this seems more handy:
values(cf, type = "tbl")
# We can see the sql code by using `show_query`:
show_query(cf)
# identical
show_query(values(cf, type = "tbl"))
# adding a key often is handy in a database
cf <- confront(tbl_income, rules, key = "id")
print(cf)
values(cf, type="tbl")
# sparse results in db
cf_sparse <- confront(tbl_income, rules, sparse=TRUE)
values(cf_sparse, type="tbl")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.