dbRead | R Documentation |
Reads a population database file (population, births, deaths) in default database format
(Year, Type, TypeID, Age, Male, Female, Total) and returns data. Database path can be either
a full path to a csv database file with the correct columns, or a vector including the type,
region and year of database to be used through getDBPath
. For example,
db_path = c("estimates", "HA", "19") would read the July 1st 2019 population estimates database
for Local Health Areas. Format of loaded data can be adjusted to default, long or wide and
pre-filtered for specific age groups.
Note that dbCheck
is run before reading the file. User will be warned if any database
checks fail.
dbRead( db_path, return_format = "default", age_filter = NULL, db_check = TRUE, full_BC = TRUE )
db_path |
Either vector of database type ("estimates", "projections", "births", "deaths"), region code and two-character year OR full path to database csv file. |
return_format |
Format of returned data.frame. Default is the same columns as default database format (Year, Type, TypeID, Age, Male, Female, Total), long format gathers sex as a new column (Year, Type, TypeID, Age, Sex, N), wide format gathers sex as a new column and spreads ages as columns (Year, Type, TypeID, Sex, 0, 1,... 89, 90+, Total). Allowed values are "default", "long" or "wide". Default = "default". |
age_filter |
Filters ages based on input vector before returning data in requested format. Must be a vector. Default = NULL. |
db_check |
Logical value whether to run |
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. |
The complete list of region IDs and ages for each type of database (population, deaths, births)
can be found in dbutils
. For historical reasons, population data is saved as
POPRREYY (population estimates), POPRRPYY (population projections), BIRRRYY (births) or
DEARRYY (deaths), where RR is the shorthand for the region code, and YY is the last two digits
of the year.
A data.frame object in the requested format.
Sebastien Lavoie (formerly, BC Stats)
Overall package documentation: dbutils
()
Other database access helpers:
dbCheck()
,
dbInfo()
,
dbWrite()
,
getDBPath()
dbRead(c("estimates", "HA", "19"), return_format = "wide", age_filter = c(0, 1, 2, 3, 4, -999)) ## Not run: dbRead("I://PopulationR/Database/Estimates/POPHAE19.csv", return_format = "wide", age_filter = c(0, 1, 2, 3, 4, -999)) ## End(Not run) dbRead(c("births", "HA", "19"), db_check = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.