values-tbl_validation-method: Retrieve the result of a validation/confrontation

values,tbl_validation-methodR Documentation

Retrieve the result of a validation/confrontation

Description

Retrieve the result of a validation/confrontation.

Usage

## S4 method for signature 'tbl_validation'
values(
  x,
  simplify = type == "matrix",
  drop = FALSE,
  type = c("tbl", "matrix", "list", "data.frame"),
  sparse = x$sparse,
  ...
)

Arguments

x

tbl_validation(), result of a confront() of tbl with a rule set.

simplify

only use when type = "list" see validate::values

drop

not used at the moment

type

whether to return a list/matrix or to return a query on the database.

sparse

whether to show the results as a sparse query (only fails and NA) or all results for each record.

...

not used

Details

Since the validation is done on a database, there are multiple options for storing the result of the validation. The results show per record whether they are valid according to the validation rules supplied.

  • Use compute (see confront.tbl_sql()) to store the result in the database

  • Use sparse to only calculate "fails" and "missings"

Default type "tbl" is that everything is "lazy", so the query and/or storage has to be done explicitly by the user. The other types execute the query and retrieve the result into R. When this creates memory problems, the tbl option is to be preferred.

Results for type:

  • tbl: a dbplyr::tbl_dbi object, pointing to the database

  • matrix: a R matrix, similar to validate::values().

  • list: a R list, similar to validate::values().

  • data.frame: the result of tbl stored in a data.frame.

Value

depending on type the result is different, see details

See Also

Other validation: confront.tbl_sql(), tbl_validation-class

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)
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! (we have to use a key, because a db...)
cf <- confront(tbl_income, rules, key = "id")
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"))

# sparse results in db (that the default)
values(cf, type="tbl", sparse=TRUE)

# or if you like data.frames
values(cf, type="data.frame", sparse=TRUE)

data-cleaning/validatedb documentation built on June 11, 2022, 4:33 p.m.