MountainMath
  • About
  • Blog

canpumf

R package for ingesting and working with Statistics Canada Public Use Microdata Files (PUMF).

canpumf is an R package that facilitates ingesting, organizing, and working with Statistics Canada Public Use Microdata Files (PUMF) in R. PUMF datasets provide individual-level survey and census records — but they ship as fixed-width or CSV files with separate metadata that must be parsed and applied by hand, which makes them awkward to work with directly.

The package automates that friction: it downloads PUMF files when needed, parses the accompanying metadata, applies value labels, and imports the data into a local DuckDB database for efficient querying. Data is returned as lazy dplyr tables, so large microdata files can be filtered and summarised without loading everything into memory. Coded column names are kept by default, with human-readable labels available on demand via label_pumf_columns().

It covers a wide range of StatCan microdata — the Labour Force Survey, the Census of Population (1971–2021), the General Social Survey, and the Canadian Income, Housing, and Financial Security surveys, among others — with configurable local caching to avoid repeated downloads.

View canpumf Documentation