Package 'cmhc'

Title: Access, Retrieve, and Work with CMHC Data
Description: Wrapper around the Canadian Mortgage and Housing Corporation (CMHC) web interface. It enables programmatic and reproducible access to a wide variety of housing data from CMHC.
Authors: Jens von Bergmann [aut, cre]
Maintainer: Jens von Bergmann <[email protected]>
License: MIT + file LICENSE
Version: 0.2.9
Built: 2024-11-05 18:40:46 UTC
Source: https://github.com/mountainmath/cmhc

Help Index


A list of CMHC quality indicators

Description

Data obtained via this package will automatically translate internal CMHC quality labels using this translation vector, this named vector is useful when working with CMHC data obtained from other sources like sporadic excel sheets or data scraped from PDF reports.

Usage

cmhc_quality_labels

Format

A named vector to translate internal CMHC quality indicators to plain text.


Access CMHC data via the HMIP.

Description

The data access needs to specify the survey, series, dimension (if any), and breakdown to specify the CMHC table to pull the data from. The 'list_cmhc_tables()' function can be used to list all the tables available via this package. Snapshot data needs to specify the year, or if it is monthly data the month. Time series data, i.e. when 'breakdown="Historical Time Series' is specified, does not need year or month parameters, but may have the frequency parameter set. Filters provide additional ways to filter the tables by sub-categories.

Usage

get_cmhc(
  survey,
  series,
  dimension,
  breakdown,
  geoFilter = "Default",
  geo_uid,
  year = NULL,
  quarter = NULL,
  month = NULL,
  frequency = NULL,
  filters = list(),
  refresh = FALSE
)

Arguments

survey

The CMHC survey, one of "Scss", "Rms", "Srms", and "Seniors", consult 'list_cmhc_surveys()' for possible values. (Other surveys and more data series may be supported in future versions.)

series

The CMHC data series of the survey, consult 'list_cmhc_series()' for possible values.

dimension

The dimension to show in the results, consult 'list_cmhc_dimensions()' for possible values.

breakdown

The geographic breakdown, one of "Survey Zones", "Census Subdivision", "Neighbourhoods", "Census Tracts", if querying data for a snapshot in time or "Historical Time Periods" if querying time series data. Not all geographic breakdowns are available for all series. returns data frame with CMHC data, tile and subtitle are set as attributes. Consult 'list_cmhc_breakdowns()' for possible values.

geoFilter

optional geographic type, only relevaent for provincial and Canada-wide tables. Options are "Default" (the default) which considers accesses the default tables which should be used for data at the metro area or finer geographies. The other designaters are only useful when used in conjunction with 'geo_uid's for provinces or all of Canada. Specifying "All" will give data for all sub-regions, "Metro", which only considers data in metro areas, "50k" and "10k", which only considers data from metro areas and agglomerations with at least 50k or 10k people, respectively.

geo_uid

Census geographic identifier for which to query the data. Can be a census tract, census subdivision, or census metropolitan area.

year

optional, only needed when querying data for a snapshot in time.

quarter

optional, only needed when querying data for a snapshot in time querying quarterly data.

month

optional, only needed when querying data for a snapshot in time.

frequency

optional, only needed when querying time series data, one of "Monthly", "Quarterly" or "Annual".

filters

optional list of filters, consult 'list_cmhc_filters()' for possible values.

refresh

optional, refresh the temporary local cache of the CMHC tables. Defaults to 'FALSE'.

Value

A tibble with the data in long form.

Examples

## Not run: 
data <- get_cmhc("Rms","Vacancy Rate","Bedroom Type","Historical Time Periods","5915022")

## End(Not run)

Get CMHC geographies for CMHC Survey Zones and Neighbourhoods

Description

The data can be queried for Census Tracts, Survey Zones, Neighbourhoods, Census Subdivisions and Metropolitan Areas, but it's most useful for Survey Zones, Neighbourhoods which are particular to CMHC and not available from other sources. The geographic data corresponds to an extract from 2017, and won't necessarily match regions from other years. The Survey Zones and Neighbourhoods have been quite stable, but census geographies change over time and can be matched with geographic data obtained by using the 'cancensus' package.

The geographic data is quite large and a local cache directory needs to be provided. By default the "CMHC_CACHE_PATH" environment variable is used to determine the cache directory, it can be set via the 'set_cache_path' function. The geographic data will take up about 55Mb of disk space.

Usage

get_cmhc_geography(
  level = c("CT", "ZONE", "NBHD", "CSD", "MET"),
  base_directory = Sys.getenv("CMHC_CACHE_PATH")
)

Arguments

level

aggregation level for geographic data, one of "CT","ZONE","NBHD","CSD","MET"

base_directory

local directory to hold CMHC geography data, by default this is inferred from the CMHC_CACHE_PATH environment variable. To use this function a local data directory has to be set.

Value

A spatial data frame with the geographies for the specified geographic level.

Examples

## Not run: 
get_cmhc_geography("ZONE")

## End(Not run)

List available CMHC breakdowns

Description

List available CMHC breakdowns

Usage

list_cmhc_breakdowns(survey = NULL, series = NULL, dimension = NULL)

Arguments

survey

Optional survey to filter by

series

Optional series to filter by

dimension

Optional dimension to filter by

Value

A data frame with survey names, series names, dimension names and available series breakdowns.

Examples

list_cmhc_breakdowns("Rms","Vacancy Rate","Bedroom Type")

List available CMHC dimensions

Description

List available CMHC dimensions

Usage

list_cmhc_dimensions(survey = NULL, series = NULL)

Arguments

survey

Optional survey to filter by

series

Optional series to filter by

Value

A data frame with survey names, series names, and available dimension names.

Examples

list_cmhc_dimensions("Rms","Vacancy Rate")

List available CMHC filters

Description

List available CMHC filters

Usage

list_cmhc_filters(
  survey = NULL,
  series = NULL,
  dimension = NULL,
  breakdown = NULL
)

Arguments

survey

Optional survey to filter by

series

Optional series to filter by

dimension

Optional dimension to filter by

breakdown

Optional breakdown to filter by

Value

A data frame with available filters

Examples

list_cmhc_filters("Rms","Vacancy Rate","Bedroom Type","Historical Time Periods")

List available CMHC series

Description

List available CMHC series

Usage

list_cmhc_series(survey = NULL)

Arguments

survey

Optional survey to filter by

Value

A data frame with survey names, and available series names.

Examples

list_cmhc_series("Rms")

List available CMHC surveys

Description

List available CMHC surveys

Usage

list_cmhc_surveys()

Value

A data frame with available survey names.

Examples

list_cmhc_surveys()

List available CMHC tables

Description

List available CMHC tables

Usage

list_cmhc_tables(short = TRUE)

Arguments

short

Logical, determines how much detail is returned. Default is 'TRUE'.

Value

A tibble listing all available CMHC data tables

Examples

list_cmhc_tables()

Interactive table selector

Description

Interactive table selector

Usage

select_cmhc_table()

Value

A string containing the function call to access the selected table

Examples

## Not run: 
select_cmhc_table()

## End(Not run)

Set persistent cmhc cache location for geographic data

Description

The cmhc package provides access to custom cmhc geographies, these are large files and should be stored in a permanent location. This function sets the CMHC_CACHE_PATH environment variable and optionally installs it in the .Renviron file for future use. This is only needed when using the 'get_cmhc_geography()' function.

Usage

set_cmhc_cache_path(cache_path, overwrite = FALSE, install = FALSE)

Arguments

cache_path

a local directory to use for saving cached data

overwrite

Option to overwrite any existing cache path already stored locally.

install

Option to install permanently for use across sessions.

Value

a character string with the CMHC cache path

Examples

## Not run: 
# This sets the cache path for the duration of the current session
set_cmhc_cache_path("~/cmhc_cache")

# This will set the cache path permanently until overwritten again
set_cmhc_cache_path("~/cmhc_cache", install = TRUE)

## End(Not run)

View saved cache directory path

Description

View saved cache path

Usage

show_cmhc_cache_path()

Value

a character string with the CMHC cache path

Examples

show_cmhc_cache_path()