dbCheck: Check population database for errors

View source: R/dbAccess.R

dbCheckR Documentation

Check population database for errors

Description

Checks a database for specific errors, at loading (dbRead, dbInfo), after raking (dbRake), or before saving (dbWrite).

  1. Database must have 7 columns: Year, Type, TypeID, Age, Male, Female, and Total.

  2. Each Year of data must have the same number of occurrences.

  3. Years of data must be continuous (no year can be missing).

  4. The Total column must equal the sum of the Male and Female columns.

  5. All combinations of region's TypeID, Age and sex must be included (even if N = 0).

  6. For Females: (a) the sum over all age groups must be equal (i.e., single age groups add to total (-999), (b) "ages and over" are sum of corresponding single ages, and, (c) 5-year age groups are sum of corresponding single ages).

  7. For Males: (a) the sum over all age groups must be equal (i.e., single age groups add to total (-999), (b) "ages and over" are sum of corresponding single ages, and, (c) 5-year age groups are sum of corresponding single ages).

  8. For Total: (a) the sum over all age groups must be equal (i.e., single age groups add to total (-999), (b) "ages and over" are sum of corresponding single ages, and, (c) 5-year age groups are sum of corresponding single ages).

  9. For database with full coverage of BC (i.e., full_BC = TRUE), the sum of all regions must equal region 0 (BC) for each age and gender.

Also, warns user if database has NO older age groups (i.e., negative ages ending in 0 or 5) and/or, if database has NO 5-year age groups (i.e., negative ages ending in 4 or 9).

Usage

dbCheck(db, full_BC = TRUE)

Arguments

db

Data variable containing the database to be checked.

full_BC

Logical value whether the region covers all of BC. Those regions (e.g., CMAs) that do not cover all of BC have full_BC = FALSE, and their sum is not checked against the BC total. Default = TRUE.

Value

db_ok Logical value. If the database passes all checks, db_ok = TRUE. Otherwise, any error(s) will be printed to screen and db_ok will be set to FALSE.

Author(s)

Sebastien Lavoie (formerly, BC Stats); Julie Hawkins, BC Stats

See Also

Overall package documentation: dbutils()

Other database access helpers: dbInfo(), dbRead(), dbWrite(), getDBPath()

Examples

## Not run:    dbCheck(db = "I:/VITAL/Database/Births/BIRHA19.csv", full_BC = TRUE)   
## Not run:    dbCheck("I:/PopulationR/Database/Projections/POPHAP19.csv")   

bcgov/dbutils documentation built on Sept. 30, 2022, 12:04 a.m.