dbWrite | R Documentation |
Writes a population database file (population, births, deaths). Data format is kept consistent with columns always including Year, Type, TypeID, Age, Male, Female, Total, in this order. As well, population databases include all possible region IDs and ages, even if that means a Male/Female/Total with N = 0.
Database output path does not have to be specified. The paths are hard-coded to ensure data is
kept in the correct location. All that is needed is a database type (population estimates,
population projections, deaths or births), the two-digit region code and the last two-digits of
the database year based on a July 1st reference date. This is enough to figure out the full path
of the database through the getDBPath
function.
Note that dbCheck
is run before writing the file. User will be warned if any database
checks fail.
dbWrite(db, db_path, overwrite = FALSE, full_BC = TRUE)
db |
Data variable containing the database to be written. Expects data to be in data.frame with columns: Year, Type, TypeID, Age, Male, Female, Total. |
db_path |
Either vector of database type ("estimates", "projections", "births", "deaths"), region code and two-character year OR full path to database csv file. |
overwrite |
Whether to overwrite the file if a database already exists. Default = FALSE. |
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.
Sebastien Lavoie (formerly, BC Stats)
Overall package documentation: dbutils
()
Other database access helpers:
dbCheck()
,
dbInfo()
,
dbRead()
,
getDBPath()
## Not run: dbWrite(data, c("estimates", "CF", "19"), overwrite = FALSE) ## Not run: dbWrite(data, "I://PopulationR/Database/Estimates/POPCFE19.csv", overwrite = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.