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

Description

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...).

Usage

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

Arguments

provID

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

item

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

fixup

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.

Details

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.

Value

data.frame of the data item is invisibly returned

Examples

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

## End(Not run)


HMDHFDplus documentation built on July 9, 2023, 6:26 p.m.