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 |
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.
cmhc_quality_labels
cmhc_quality_labels
A named vector to translate internal CMHC quality indicators to plain text.
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.
get_cmhc( survey, series, dimension, breakdown, geoFilter = "Default", geo_uid, year = NULL, quarter = NULL, month = NULL, frequency = NULL, filters = list(), refresh = FALSE )
get_cmhc( survey, series, dimension, breakdown, geoFilter = "Default", geo_uid, year = NULL, quarter = NULL, month = NULL, frequency = NULL, filters = list(), refresh = FALSE )
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'. |
A tibble with the data in long form.
## Not run: data <- get_cmhc("Rms","Vacancy Rate","Bedroom Type","Historical Time Periods","5915022") ## End(Not run)
## Not run: data <- get_cmhc("Rms","Vacancy Rate","Bedroom Type","Historical Time Periods","5915022") ## End(Not run)
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.
get_cmhc_geography( level = c("CT", "ZONE", "NBHD", "CSD", "MET"), base_directory = Sys.getenv("CMHC_CACHE_PATH") )
get_cmhc_geography( level = c("CT", "ZONE", "NBHD", "CSD", "MET"), base_directory = Sys.getenv("CMHC_CACHE_PATH") )
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. |
A spatial data frame with the geographies for the specified geographic level.
## Not run: get_cmhc_geography("ZONE") ## End(Not run)
## Not run: get_cmhc_geography("ZONE") ## End(Not run)
List available CMHC breakdowns
list_cmhc_breakdowns(survey = NULL, series = NULL, dimension = NULL)
list_cmhc_breakdowns(survey = NULL, series = NULL, dimension = NULL)
survey |
Optional survey to filter by |
series |
Optional series to filter by |
dimension |
Optional dimension to filter by |
A data frame with survey names, series names, dimension names and available series breakdowns.
list_cmhc_breakdowns("Rms","Vacancy Rate","Bedroom Type")
list_cmhc_breakdowns("Rms","Vacancy Rate","Bedroom Type")
List available CMHC dimensions
list_cmhc_dimensions(survey = NULL, series = NULL)
list_cmhc_dimensions(survey = NULL, series = NULL)
survey |
Optional survey to filter by |
series |
Optional series to filter by |
A data frame with survey names, series names, and available dimension names.
list_cmhc_dimensions("Rms","Vacancy Rate")
list_cmhc_dimensions("Rms","Vacancy Rate")
List available CMHC filters
list_cmhc_filters( survey = NULL, series = NULL, dimension = NULL, breakdown = NULL )
list_cmhc_filters( survey = NULL, series = NULL, dimension = NULL, breakdown = NULL )
survey |
Optional survey to filter by |
series |
Optional series to filter by |
dimension |
Optional dimension to filter by |
breakdown |
Optional breakdown to filter by |
A data frame with available filters
list_cmhc_filters("Rms","Vacancy Rate","Bedroom Type","Historical Time Periods")
list_cmhc_filters("Rms","Vacancy Rate","Bedroom Type","Historical Time Periods")
List available CMHC series
list_cmhc_series(survey = NULL)
list_cmhc_series(survey = NULL)
survey |
Optional survey to filter by |
A data frame with survey names, and available series names.
list_cmhc_series("Rms")
list_cmhc_series("Rms")
List available CMHC surveys
list_cmhc_surveys()
list_cmhc_surveys()
A data frame with available survey names.
list_cmhc_surveys()
list_cmhc_surveys()
List available CMHC tables
list_cmhc_tables(short = TRUE)
list_cmhc_tables(short = TRUE)
short |
Logical, determines how much detail is returned. Default is 'TRUE'. |
A tibble listing all available CMHC data tables
list_cmhc_tables()
list_cmhc_tables()
Interactive table selector
select_cmhc_table()
select_cmhc_table()
A string containing the function call to access the selected table
## Not run: select_cmhc_table() ## End(Not run)
## Not run: select_cmhc_table() ## End(Not run)
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.
set_cmhc_cache_path(cache_path, overwrite = FALSE, install = FALSE)
set_cmhc_cache_path(cache_path, overwrite = FALSE, install = FALSE)
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. |
a character string with the CMHC cache path
## 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)
## 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 path
show_cmhc_cache_path()
show_cmhc_cache_path()
a character string with the CMHC cache path
show_cmhc_cache_path()
show_cmhc_cache_path()