updateAppData: Update population app data

View source: R/dbApp.R

updateAppDataR Documentation

Update population app data

Description

Read multiple databases, of the same year, to create a combined updated database for the Population Estimates and Projections apps.

Usage

updateAppData(dbType, dbYear, RegionTypes = "default", RegionNamesFile)

Arguments

dbType

Type of database being written. Possible values are "estimates" or "projections".

dbYear

Two-digit year of the data being saved. Based on July 1st reference date, as character.

RegionTypes

A dataframe with two character columns: ID and Region.Type. Default = "default" which internally sets ID and Region.Type as follows:

  • ID: Two-digit region code of the databases. Values include: "RD", "SD", "HY", "CF",

  • Region.Type: Full text name of region type. Values include: "Regional District", "School District", "Health Authority", "Children and Family Development", "Health Service Delivery Area", "Local Health Area", "Development Region", "College Region", "Special Regions (CMAs and Vancouver Island)", and "Community Health Service Area"). Note that "Children and Family Development" and "College Region" are only for projections.

RegionNamesFile

The name (including extension, either .csv or .xlsx) of the lookupfile of Region names (e.g., 'Lookup_Region_Names.csv'). This file must be located in the ConversionTables folder (i.e., dbPaths$conv_tbl_path, "//SFP.IDIR.BCGOV/S152/S52004/ConversionTables/").

Details

The Population Estimates and Projections apps provide corresponding data for the region type, region(s), year(s), gender(s), and age(s) selected by the app's user. Once the user chooses one of the 8 available Region Types, they then select whichever of that Region Type's Regions they want, for whichever Year(s) of data are available, for any combination of Males, Females, Totals. They then choose either Single Year Age Groups (0, 1, 2, ..., 88, 89, 90+), 5-Year Age Groups (LT1, 1-4, 5-9, ..., 80-84, 85-89, 90+), Totals, or create Custom Age Groups. They can then generate the output on-screen and/or download the data as a csv.

A lookup table of full text region names for region types must be in the "I:/ConversionTables/" folder, as either a csv or xlsx file type, with columns "TypeID", "Type" and "Region.Name".

The app takes this function's return output and calculates 5-year age groups or custom age groups as requested by the user. Therefore, the return output need only include individual and total age data (i.e., 0, 1, 2, ..., 88, 89, 90+).

This function replaces the analysis portion of popApp and popPropjApp. Instead, call this function, save the resulting output as data1.rds in the corresponding .../app/data folder, then open app.R to deploy the updated app. (The popApp and popProjApp Rprojects are at 'I:/PEOPLEPROJECTIONS/00 - R_code/shiny_apps/Production/'.)

Value

A data.frame object with variables: Region, Region.Name, Region.Type, Year, Gender, Total, individual age columns (e.g., 0, 1, 2, ..., 89), age group columns (e.g., 0-4, 5-9, 90+). Region.Name is the text version of the Region (e.g., "British Columbia" for Region 0), and Gender is the first initial of the gender values (e.g., M, F, T). Data type is either projections or estimates.

See Also

Overall package documentation: dbutils()

Examples

## Not run:   updateAppData(dbType = "estimates", dbYear = "19",
                         RegionTypes = data.frame(ID = c("RD", "DR"),
                                       Region.Type = c("Regional District", "Development Region"),
                                       stringsAsFactors = FALSE),
                         RegionNamesFile = "Lookup_Region_Names.csv")  
## End(Not run)
## Not run:   updateAppData(dbType = "projections", dbYear = "19", RegionTypes = "default",
                         RegionNamesFile = "Lookup_Region_Names.csv")  
## End(Not run)

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