Skip to contents

Checks your loanbook is as we expect

Usage

check_loanbook(loanbook)

Arguments

loanbook

A loanbook dataframe like demo_loanbook.

Value

Called for it's side effects. Returns loanbook invisibly.

Examples

library(vroom)
library(dplyr, warn.conflicts = FALSE)

loanbook <- vroom(example_file("demo_loanbook.csv"), show_col_types = FALSE)
check_loanbook(loanbook)
#> Found duplicate(s) on columns company_name, postcode, country of the data set.
#>  Found for the company Peasant Peter, postcode: 01234, country: germany
#>  Please check if these duplicates are intended and have an unique id.

# Do you have the expected columns?
bad_name <- rename(loanbook, ids = id)
try(check_loanbook(bad_name))
#> Error in abort_missing_names(sort(setdiff(expected_names, names(x)))) : 
#>   Must have missing names:
#> `id`

# Do you have any duplicates in the column `id`?
bad_id <- bind_rows(loanbook, slice(loanbook, 1))
try(check_loanbook(bad_id))
#> Error in check_loanbook(bad_id) : has_no_duplicates is not TRUE

# Do you have missing values (`NA`s) in non-nullable columns?
# styler: off
missing_id <- tribble(
  ~id,            ~company_name, ~postcode,  ~country, ~misc_info,
   NA, "John Meier's Groceries",   "55555", "germany",        "Y",
   11, "John Meier's Groceries",   "55555",  "norway",        "Y"
)
# styler: on
try(check_loanbook(missing_id))
#> Error in abort_if_incomplete(., non_nullable) : 
#>   Non-nullable columns must not have `NA`s.
#>  Columns to review: id