readCHMDweb: read data from the Canadian Human Mortality Database into R

View source: R/readHMD.R

readCHMDwebR Documentation

read data from the Canadian Human Mortality Database into R


CHMD data are formatted exactly as HMD data. This function simply parses the necessary url together given a province code and data item (same nomenclature as HMD). Data is parsed using HMDparse(), which converts columns into useful and intuitive classes, for ready-use. See ?HMDparse for more information on type conversions. No authentication is required for this database. Only a single item/prefecture is downloaded. Loop for more complex calls (See examples). The provID is not appended as a column, so be mindful of this if appending several items together into a single data.frame. Note that at the time of this writing, the finest Lexis resolution for prefectural lifetables is 5x5 (5-year, 5-year age groups). Raw data are, however, provided in 1x1 format, and deaths are also available in triangles. Note that cohort data are not produced for Canada at this time (but you could produce such data by starting with the Deaths\_Lexis file...).


readCHMDweb(provID = "can", item = "Deaths_1x1", fixup = TRUE, ...)



a single provID 3 character string, as returned by getCHMDprovinces().


the statistical product you want, e.g., "fltper_5x5". Only 1.


logical. Should columns be made more user-friendly, e.g., forcing Age to be integer?


extra arguments ultimately passed to read.table(). Not likely needed.


This database is curated independently from the HMD/HFD family, and so file types and locations may be subject to change. If this happens, please notify the package maintainer.


data.frame of the data item is invisibly returned


## Not run: 
# grab province codes (including All Canada)
provs <- getCHMDprovinces()
# grab all mltper_5x5  
# and stick into long data.frame: 
mltper <-, lapply(provs, function(provID){
                   Dat        <- readCHMDweb(provID = provID, item = "mltper_5x5", fixup = TRUE)
                   Dat$provID <- provID

## End(Not run)

HMDHFDplus documentation built on Feb. 16, 2023, 8:34 p.m.