#### global variables ----
## https://r-pkgs.org/package-within.html#echo-a-working-package
## When using dplyr and unquoted variable names inside a package, a note is generated that:
## fun.name: no visible binding for global variable 'myVar'
## To address this, the global variables have been set here.
# Database paths ----
drive_path <- "//SFP.IDIR.BCGOV/S152/S52004/"
est_path <- paste0(drive_path, "PopulationR/Database/Estimates/")
proj_path <- paste0(drive_path, "PopulationR/Database/Projections/")
dea_path <- paste0(drive_path, "VITAL/Database/Deaths/")
bir_path <- paste0(drive_path, "VITAL/Database/Births/")
pop_path <- paste0(drive_path, "PopulationR/Database/")
conv_tbl_path <- paste0(drive_path, "ConversionTables/")
dbPaths <- list(est_path, proj_path, dea_path, bir_path, pop_path, conv_tbl_path)
names(dbPaths) <- c("est_path", "proj_path", "dea_path", "bir_path", "pop_path", "conv_tbl_path")
rm(drive_path, est_path, proj_path, dea_path, bir_path, pop_path, conv_tbl_path)
# Region IDs ----
## This is not all possible region types, just common ones.
RD_id <- c(0, 1, 3, 5, 7, 9, 15, 17, 19, 21, 23, 24, 26, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45,
47, 49, 51, 53, 55, 57, 59)
CS_id <- c(0, 1006, 1012, 1017, 1019, 1022, 1028, 1035, 1037, 1039, 1040, 1043, 1046, 1048, 1801,
1802, 1803, 1804, 1805, 1806, 3004, 3010, 3011, 3013, 3015, 3017, 3019, 3023, 3027,
3032, 3039, 3041, 3043, 3045, 3047, 3050, 3052, 3056, 3058, 3060, 3807, 5005, 5009,
5014, 5018, 5023, 5026, 5030, 5032, 5037, 5042, 5050, 5052, 5054, 7005, 7009, 7014,
7022, 7024, 7026, 7028, 7035, 7041, 7047, 7049, 7051, 7053, 7055, 7801, 7802, 7803,
7805, 7806, 7807, 7808, 7809, 9009, 9014, 9016, 9020, 9027, 9032, 9034, 9035, 9036,
9048, 9052, 9056, 9060, 9062, 9804, 9805, 9806, 9807, 9808, 9809, 9810, 9812, 9814,
9815, 9816, 9817, 9818, 9819, 9821, 9824, 9825, 9826, 9827, 9830, 9831, 9832, 9833,
9834, 9835, 9836, 9837, 9838, 9839, 9841, 9842, 9843, 9844, 9845, 9847, 9848, 9849,
9850, 9852, 9875, 9876, 9877, 9878, 9879, 9880, 9881, 9882, 9883, 9884, 9885, 15001,
15002, 15004, 15007, 15011, 15015, 15020, 15022, 15025, 15029, 15034, 15036, 15038,
15039, 15043, 15046, 15051, 15055, 15062, 15065, 15070, 15075, 15801, 15802, 15803,
15804, 15805, 15806, 15807, 15808, 15809, 15810, 15811, 15813, 15816, 15825, 15830,
15835, 15840, 17005, 17010, 17015, 17021, 17027, 17029, 17030, 17034, 17040, 17041,
17042, 17044, 17047, 17049, 17052, 17054, 17056, 17801, 17802, 17803, 17804, 17805,
17809, 17811, 17812, 17815, 17819, 19008, 19012, 19013, 19015, 19016, 19017, 19021,
19033, 19035, 19043, 19046, 19049, 19051, 19801, 19802, 19803, 19804, 19808, 19809,
19811, 19812, 19814, 19815, 19816, 19817, 19818, 19820, 19821, 19822, 21007, 21008,
21010, 21014, 21016, 21018, 21023, 21030, 21032, 21034, 21036, 21804, 21805, 21806,
21807, 23008, 23019, 23025, 23033, 23035, 23037, 23039, 23047, 23049, 23801, 23802,
23803, 23804, 23805, 23806, 23807, 23808, 23809, 23810, 23813, 23814, 23816, 23822,
23823, 23824, 23825, 24025, 24029, 24030, 24034, 24039, 24042, 24048, 24052, 24054,
24803, 24804, 24805, 24806, 24812, 24813, 24814, 24817, 24818, 24820, 24833, 24835,
24836, 24840, 26005, 26010, 26014, 26021, 26022, 26024, 26801, 26802, 27008, 27010,
27012, 27016, 27018, 27020, 27802, 27806, 29005, 29011, 29018, 29022, 29024, 29026,
29028, 29801, 29803, 31006, 31012, 31017, 31020, 31021, 31026, 31032, 31034, 31801,
31802, 31806, 31807, 31808, 31809, 31812, 31813, 31814, 31815, 31816, 31817, 31818,
31819, 31820, 31821, 31822, 31823, 31824, 31826, 31827, 31828, 31829, 31831, 31832,
31833, 31842, 31843, 31844, 33006, 33008, 33012, 33015, 33019, 33024, 33028, 33032,
33035, 33037, 33039, 33042, 33044, 33045, 33054, 33060, 33067, 33068, 33070, 33072,
33074, 33801, 33802, 33803, 33805, 33806, 33807, 33808, 33809, 33810, 33811, 33812,
33813, 33814, 33817, 33819, 33821, 33823, 33824, 33825, 33828, 33829, 33831, 33832,
33833, 33834, 33836, 33837, 33839, 33840, 33841, 33842, 33844, 33845, 33846, 33848,
33849, 33850, 33851, 33852, 33853, 33854, 33855, 33857, 33858, 33859, 33861, 33865,
33866, 33868, 33870, 33872, 33873, 33874, 33875, 33876, 33877, 33878, 33879, 33880,
33881, 33882, 33884, 33886, 33887, 33888, 33889, 33895, 33896, 33897, 33898, 35010,
35012, 35016, 35018, 35020, 35029, 35801, 35802, 35803, 37005, 37010, 37014, 37017,
37021, 37022, 37023, 37024, 37028, 37033, 37041, 37801, 37802, 37803, 37805, 39007,
39011, 39019, 39023, 39032, 39037, 39039, 39043, 39044, 39045, 39801, 39802, 39803,
39804, 39805, 39806, 39807, 39808, 39811, 41005, 41009, 41010, 41012, 41013, 41014,
41015, 41016, 41017, 41019, 41021, 41025, 41026, 41027, 41039, 41041, 41801, 41802,
41803, 41804, 41805, 41806, 41807, 41808, 41809, 41810, 41811, 41812, 41813, 41817,
41818, 41821, 41827, 41828, 41829, 41831, 41833, 41834, 41835, 41837, 41838, 41839,
41840, 41841, 41844, 41845, 41848, 41849, 41850, 41851, 41852, 41854, 41855, 41856,
41858, 41859, 41860, 41861, 41862, 41863, 41864, 41866, 41868, 41871, 41872, 41873,
41876, 41879, 41880, 41881, 41882, 41883, 41884, 41885, 43008, 43012, 43017, 43023,
43027, 43031, 43033, 43037, 43804, 43806, 43807, 43808, 43809, 43813, 43815, 43816,
43817, 43835, 43836, 43837, 45006, 45010, 45012, 45014, 45801, 45802, 45803, 47007,
47012, 47016, 47021, 47023, 47026, 47027, 47030, 47032, 47803, 47804, 47806, 47807,
47809, 47810, 49005, 49011, 49013, 49018, 49020, 49022, 49024, 49028, 49032, 49035,
49038, 49039, 49041, 49802, 49803, 49804, 49805, 49807, 49810, 49811, 49812, 49813,
49814, 49815, 49816, 49817, 49818, 49819, 49820, 49832, 49843, 49844, 49845, 49846,
49847, 51007, 51009, 51013, 51015, 51017, 51019, 51022, 51028, 51031, 51032, 51034,
51038, 51043, 51051, 51053, 51801, 51802, 51803, 51804, 51805, 51806, 51807, 51809,
51810, 51811, 51813, 51814, 51815, 51818, 51819, 51820, 51821, 51822, 51823, 51824,
51825, 51826, 51827, 51828, 51829, 51830, 51833, 51840, 51844, 51845, 51846, 51847,
51848, 51849, 53007, 53012, 53019, 53023, 53033, 53038, 53042, 53044, 53046, 53048,
53050, 53801, 53802, 55003, 55005, 55010, 55014, 55021, 55023, 55025, 55030, 55034,
55040, 55042, 55801, 55802, 55803, 55804, 55807, 55808, 55812, 57022, 57802, 57803,
57804, 57813, 57814, 59007, 59805, 59806, 59809, 59810)
CA_id <- c(0, 11, 12, 13, 21, 22, 23, 24, 25, 31, 32, 41, 42, 43)
SD_id <- c(0, 5, 6, 8, 10, 19, 20, 22, 23, 27, 28, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 57, 58, 59, 60, 61, 62, 63, 64, 67, 68, 69, 70,
71, 72, 73, 74, 75, 78, 79, 81, 82, 83, 84, 85, 87, 91, 92)
HY_id <- c(0, 1, 2, 3, 4, 5)
CF_id <- c(0, 1, 2, 3, 4)
CL_id <- c(0, 1101, 1102, 1203, 1204, 1205, 1306, 1307, 1308, 1309, 2110, 2111, 2112, 2113, 2214,
2215, 2216, 2317, 2318, 2319, 2320, 2321, 2422, 2423, 2424, 2525, 2526, 2527, 2528,
2529, 3130, 3131, 3132, 3133, 3234, 3235, 3236, 3237, 3238, 3239, 4140, 4141, 4142,
4243, 4244, 4245, 4346, 4347)
MP_id <- c(0, 59001, 59002, 59004, 59009, 59011, 59012, 59014, 59015, 59016, 59019, 59020, 59023,
59025, 59026, 59027, 59029, 59036, 59037, 59038, 59041, 59042, 59043, 59703, 59704,
59705, 59706, 59707, 59708, 59709, 59710, 59711, 59717, 59719, 59721, 59722, 59724,
59725, 59727, 59728, 59729, 59730, 59731, 59733, 59734, 59735, 59736, 59737, 59738,
59739, 59741, 59744, 59745, 59748, 59749, 59750, 59751, 59752, 59753, 59754, 59756,
59757, 59758, 59759, 59760, 59762, 59763, 59764, 59765, 59766, 59768, 59769, 59770,
59771, 59772, 59774, 59775, 59776, 59777, 59778, 59780, 59781, 59782, 59783, 59784,
59791, 59792, 59793, 59795, 59796, 59798, 59799, 59800, 59801, 59802, 59803, 59804,
59805, 59806, 59809, 59810, 59811, 59812, 59814, 59815, 59816, 59817, 59818, 59819,
59821, 59822, 59823, 59824, 59825, 59826, 59827, 59828, 59829, 59830, 59831, 59832,
59833, 59834, 59835, 59837, 59838, 59844, 59845, 59846, 59847, 59848, 59849, 59850,
59851, 59852, 59854, 59855, 59857, 59858, 59859, 59860, 59861, 59862, 59863, 59864,
59866, 59870, 59872, 59873, 59874, 59875, 59876, 59879, 59880, 59886, 59890, 59891,
59892, 59894, 59895, 59896, 59897, 59899, 59900, 59901, 59902, 59903, 59904, 59905,
59906, 59907, 59908, 59909, 59910, 59911, 59913, 59914, 59915, 59917, 59918, 59922,
59923, 59924, 59925, 59926, 59927, 59928, 59930, 59931, 59932, 59933, 59935, 59947,
59950, 59951, 59969, 59975)
ED_id <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68,
69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87)
HS_id <- c(0, 11, 12, 13, 14, 21, 22, 23, 31, 32, 33, 41, 42, 43, 51, 52, 53)
HA_id <- c(0,111,112,113,114,115,116,121,122,123,124,125,126,127,131,132,133,134,135,136,137,138,139,
141,142,143,144,145,146,147,148,149,211,212,213,214,215,221,222,223,224,231,232,233,234,
311,321,322,323,324,325,326,331,332,333,334,335,336,337,411,412,413,414,421,422,423,424,
425,426,431,432,433,434,510,511,512,513,514,515,516,517,518,519,521,522,523,524,531,532,533)
DR_id <- c(0, 1, 2, 5, 7, 6, 3, 4, 8)
PS_id <- c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)
SR_id <- c(0, 905, 907, 913, 915, 918, 920, 925, 930, 932, 933, 934, 935, 937, 938, 939, 940, 943,
944, 945, 950, 952, 955, 965, 970, 975, 977, 400, 410)
CH_id <- c(0, 1110, 1120, 1130, 1140, 1150, 1160, 1210, 1220, 1230, 1240, 1250, 1260, 1270, 1310,
1320, 1330, 1340, 1350, 1361, 1362, 1371, 1372, 1373, 1374, 1375, 1376, 1377, 1380,
1390, 1410, 1420, 1431, 1432, 1433, 1440, 1450, 1461, 1462, 1470, 1480, 1490, 2110,
2121, 2122, 2131, 2132, 2133, 2134, 2141, 2142, 2150, 2210, 2221, 2222, 2223, 2224,
2231, 2232, 2233, 2241, 2242, 2243, 2244, 2245, 2311, 2312, 2313, 2314, 2315, 2316,
2317, 2321, 2322, 2323, 2331, 2332, 2333, 2334, 2335, 2336, 2337, 2338, 2341, 2342,
3111, 3112, 3113, 3114, 3115, 3116, 3117, 3211, 3212, 3213, 3221, 3222, 3223, 3231,
3232, 3233, 3241, 3242, 3243, 3244, 3251, 3252, 3253, 3261, 3262, 3263, 3264, 3311,
3312, 3313, 3314, 3315, 3321, 3322, 3323, 3331, 3332, 3333, 3341, 3342, 3351, 3352,
3353, 3360, 3370, 4111, 4112, 4113, 4114, 4115, 4116, 4117, 4118, 4119, 4121, 4122,
4123, 4124, 4125, 4131, 4132, 4133, 4134, 4141, 4142, 4211, 4212, 4220, 4231, 4232,
4233, 4234, 4241, 4242, 4243, 4244, 4245, 4246, 4247, 4251, 4252, 4253, 4261, 4262,
4263, 4311, 4312, 4313, 4321, 4322, 4330, 4341, 4342, 4343, 5101, 5102, 5110, 5121,
5122, 5130, 5141, 5142, 5143, 5150, 5160, 5171, 5172, 5180, 5190, 5211, 5212, 5221,
5222, 5223, 5231, 5232, 5233, 5234, 5241, 5242, 5243, 5244, 5245, 5246, 5247, 5311,
5312, 5313, 5314, 5321, 5322, 5323, 5331, 5332)
VI_id <- c(0, 400) ## VAN ISLE
VN_id <- c(0, 410) ## VAN ISLE but no CRD (=VI_NO_CRD)
# regionIDs <- list(RD_id, CSD_id, CS_id, CA_id, SD_id, HY_id, CF_id, CL_id, RCMP_id, MP_id,
# PED_id, ED_id, HS_id, HA_id, DR_id, PS_id, SR_id, CH_id, VI_id, VN_id)
# names(regionIDs) <- c("RD", "CSD", "CS", "CA", "SD", "HY", "CF", "CL", "RCMP", "MP",
# "PED", "ED", "HS", "HA", "DR", "PS", "SR", "CH", "VI", "VN")
regionIDs <- list(RD_id, CS_id, CA_id, SD_id, HY_id, CF_id, CL_id, MP_id,
ED_id, HS_id, HA_id, DR_id, PS_id, SR_id, CH_id, VI_id, VN_id)
names(regionIDs) <- c("RD", "CS", "CA", "SD", "HY", "CF", "CL", "MP",
"ED", "HS", "HA", "DR", "PS", "SR", "CH", "VI", "VN")
# rm(list = ls(pattern = "_id"))
## Frank prefers more descriptive Region IDs, hence longer names in conversion tables
## need to have mapping to 2-character region codes to input as TypeID into converted databases
## longer-digit IDs for CS (=CSD), ED (=PED), MP (=RCMP)
# CSD_id <- CS_id
# PED_id <- ED_id
# RCMP_id <- MP_id
FrankNames <- data.frame(ID = c("CS", "MP", "ED", "HS", "HA", "CH", "SR",
"CF", "CM", "VI", "VN"),
ID_F = c("CSD", "RCMP", "PED", "HSDA", "LHA", "CHSA", "CHSA_MOH",
"MCFD", "CMA", "VANISLE", "VI_NO_CRD"),
stringsAsFactors = FALSE)
# RR is the region code. Region codes include, but are not limited to the following:
# • AG=Court Service Region
# • BC=British Columbia
# • CM=Census Metropolitan Areas Canada/BC CA
# • CR=College Region
# • CS=Census Subdivision
# • CH=Community Health Service Area
# • DR=Development Region
# • EA=Employment & Immigration Aggregate Areas
# • EI=Employment & Immigration Canada Region
# • EM=Environment Management Region
# • EP=Environment Planning Unit
# • ER=Economic Region
# • HA=Local Health Area
# • MH=Micro Health Region
# • MP=RCMP Region
# • MU=Municipality
# • PE=Provincial Electoral District
# • PR=Province
# • RD=Regional District
# • SR=Special Sub-Provincial Region
# • SS=Social Services Region
# • PS=College Region
# • CD=Census Division
# • SD=School District
# • CO=Ministry for Children and Family Region
# • HS=Health Service Delivery Area
# • HY=Health Authority
# • AB=Region & Aboriginal Identity
# • DA=Dissemination Areas
# • DB=Dissemination Blocks
# • ED=PEDs as of 2008
# • CF=Ministry for Children and Family Region
# Age vectors ----
popall <- c(seq(0, 109), seq(-4, -109, -5), -90, -100, -110, -999)
pop1yr90 <- c(seq(0, 89), -90, -999)
pop1yr100 <- c(seq(0, 99), -100, -999)
pop1yrOver90 <- c(seq(90, 120))
pop5yr90 <- c(seq(-4, -89, -5), -90, -999)
pop5yr100 <- c(seq(-4, -99, -5), -100, -999)
deaall <- c(seq(0, 119), seq(-4, -119, -5), -90, -120, -999)
dea1yr120 <- c(seq(0, 119), -120, -999)
dea1yr110 <- c(seq(0, 109), -110, -999)
dea1yr90 <- c(seq(0, 89), -90, -999)
dea5yr120 <- c(seq(-4, -119, -5), -120, -999)
dea5yr110 <- c(seq(-4, -109, -5), -110, -999)
dea5yr90 <- c(seq(-4, -89, -5), -90, -999)
birall <- c(seq(15, 64), seq(-19, -64, -5), -65, -999)
bir1yr65 <- c(seq(15, 64), -65, -999)
bir5yr65 <- c(seq(-19, -64, -5), -65, -999)
ageLists <- list(popall, dea1yr110, pop1yr90, pop1yr100, dea5yr110, pop5yr90, pop5yr100,
deaall, dea1yr120, dea1yr90, dea5yr120, dea5yr90, birall, bir1yr65, bir5yr65,
pop1yrOver90)
names(ageLists) <- c("popall", "dea1yr110", "pop1yr90", "pop1yr100", "dea5yr110", "pop5yr90",
"pop5yr100", "deaall", "dea1yr120", "dea1yr90", "dea5yr120", "dea5yr90",
"birall", "bir1yr65", "bir5yr65", "pop1yrOver90")
rm(popall, dea1yr110, pop1yr90, pop1yr100, dea5yr110, pop5yr90, pop5yr100,
deaall, dea1yr120, dea1yr90, dea5yr120, dea5yr90, birall, bir1yr65, bir5yr65, pop1yrOver90)
# Access variables ----
# in dbCheck()
BC <- Regions <- region <- NULL
# in dbRead()
Age <- Female <- Male <- N <- Total <- TypeID <- Year <- NULL
# App variables ----
Gender <- Region.Name <- Region.Type <- ID <- NULL
# Raking variables ----
# in calc.cols()
TOTAL <- Ctrl_TOTAL <- Sum <- Diff <- NULL
# in dbRake()
Sex <- Region <- VarRow <- row_order <- TotalOldest <- NULL
# in adjustSex()
pop <- pop.x <- pop.y <- pop_diff <- adjpop <- NULL
# Conversion variables ----
# in conversiontables()
Table <- X2 <- X3 <- X4 <- NULL
# in dbConvert()
Type <- destination <- mn <- flag <- Ends <- Grps <- ID_F <- NULL
# in geogConvert()
adj_value <- TotalSource <- check <- NULL
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.