diff --git a/DESCRIPTION b/DESCRIPTION
index dae0b64b..ae507efb 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,7 +1,7 @@
Package: cancensus
Type: Package
Title: Access, Retrieve, and Work with Canadian Census Data and Geography
-Version: 0.5.5
+Version: 0.5.6
Authors@R: c(
person("Jens", "von Bergmann", email = "jens@mountainmath.ca", role = c("aut"), comment = "API creator and maintainer"),
person("Dmitry", "Shkolnik", email = "shkolnikd@gmail.com", role = c("aut", "cre"), comment = "Package maintainer, responsible for correspondence"),
@@ -24,15 +24,13 @@ Imports: digest (>= 0.1),
httr (>= 1.0.0),
jsonlite (>= 1.0),
rlang
-RoxygenNote: 7.2.1
+RoxygenNote: 7.2.3
Suggests: knitr,
ggplot2,
leaflet,
mapdeck,
rmarkdown,
readr,
- rgdal,
- rgeos,
scales,
sp,
sf,
diff --git a/NEWS.md b/NEWS.md
index 4db26f3b..bd049493 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,3 +1,10 @@
+# cancensus 0.5.6
+
+- fix issue when using named vectors to query data for non-existent geographies, return NULL in this case instead of throwing error
+- fix problem with population centre geographic data download
+- support newly released Forward Sortation Area geography for statcan geography and WDS functionality
+- remove instances of new native R pipe |> with dplyr pipe %>% to preserve compatibility with older R versions
+
# cancensus 0.5.5
- add functionality for direct access to StatCan census WDS for 2021
diff --git a/R/cancensus.R b/R/cancensus.R
index e20ad08a..a049467c 100644
--- a/R/cancensus.R
+++ b/R/cancensus.R
@@ -268,7 +268,10 @@ get_census <- function (dataset, regions, level=NA, vectors=c(), geo_format = NA
to_rename <- setNames(names(result),gsub(":.*","",names(result)))
to_rename <- to_rename[names(to_rename)!=as.character(to_rename)]
if (length(to_rename)>0) result <- result %>% dplyr::rename(!!!to_rename)
- if (!is.null(names(vectors))) result <- result %>% dplyr::rename(!!! vectors)
+ if (!is.null(names(vectors))) {
+ to_rename <- vectors[as.character(vectors) %in% names(result)]
+ if (length(to_rename)>0) result <- result %>% dplyr::rename(!!! to_rename)
+ }
}
}
diff --git a/R/census_regions.R b/R/census_regions.R
index a764b5fa..1c394be7 100644
--- a/R/census_regions.R
+++ b/R/census_regions.R
@@ -34,7 +34,9 @@
#' @export
#'
#' @examples
+#' \dontrun{
#' list_census_regions('CA16')
+#' }
list_census_regions <- function(dataset, use_cache = TRUE, quiet = FALSE) {
dataset <- translate_dataset(dataset)
cache_file <- file.path(tempdir(),paste0(dataset, "_regions.rda"))
@@ -200,16 +202,16 @@ add_unique_names_to_region_list <- function(region_list) {
dplyr::group_by(.data$name) %>%
dplyr::mutate(count=dplyr::n()) %>%
dplyr::mutate(Name=dplyr::case_when(.data$count==1 ~ name,
- TRUE ~ paste0(.data$name," (",.data$municipal_status,")"))) |>
+ TRUE ~ paste0(.data$name," (",.data$municipal_status,")"))) %>%
dplyr::group_by(.data$Name) %>%
dplyr::mutate(count=dplyr::n()) %>%
dplyr::mutate(Name=dplyr::case_when(.data$count==1 ~ Name,
- TRUE ~ paste0(.data$Name," (",.data$region,")"))) |>
- dplyr::select(-.data$count) |>
+ TRUE ~ paste0(.data$Name," (",.data$region,")"))) %>%
+ dplyr::select(-.data$count) %>%
dplyr::ungroup()
if (length(gs)>1) {
- r <- r |>
+ r <- r %>%
dplyr::group_by(dplyr::across(dplyr::all_of(gs)))
}
r
diff --git a/R/geographies.R b/R/geographies.R
index fe5ce12f..0ab321bf 100644
--- a/R/geographies.R
+++ b/R/geographies.R
@@ -5,7 +5,7 @@
#'
#' @param census_year census year to get the data for, right now only 2021 is supported
#' @param level geographic level to return the data for, valid choices are
-#' "PR","CD","CMACA","CSD","CT","ADA","DA","ER","FED","DPL","POPCNTR"
+#' "PR","CD","CMACA","CSD","CT","ADA","DA","ER","FED","DPL","POPCNTR", "FSA"
#' @param type type of geographic data, valid choices area "cartographic" or "digital"
#' @param cache_path optional path to cache the data. If the cancensus cache path is set the geographic data gets
#' cached in the "geographies" subdirectory of the cancensus cache path.
@@ -24,7 +24,7 @@ get_statcan_geographies <- function(census_year,level,type="cartographic",
cache_path = NULL,timeout=1000,
refresh=FALSE,quiet=FALSE) {
valid_census_years <- c("2021")
- valid_levels <- c("PR","CD","CMACA","CMA","CA","CSD","CT","ADA","DA","ER","FED","DPL","POPCNTR")
+ valid_levels <- c("PR","CD","CMACA","CMA","CA","CSD","CT","ADA","DA","ER","FED","DPL","POPCNTR","POPCTR","FSA")
valid_types <- c("cartographic","digital")
if (!(census_year %in% valid_census_years)) {
stop(paste0("Census year must be one of ",paste0(valid_census_years,collapse = ", "),"."))
@@ -35,7 +35,7 @@ get_statcan_geographies <- function(census_year,level,type="cartographic",
if (!(level %in% valid_levels)) {
stop(paste0("Level must be one of ",paste0(valid_levels,collapse = ", "),"."))
}
- level_map <- c("CMACA"="CMA","CA"="CMA","POPCNTR","PC")
+ level_map <- c("CMACA"="CMA","CA"="CMA","POPCNTR"="PC","POPCTR"="PC")
if (level %in% names(level_map)) level <-level_map[[level]]
geo_base_path <- cache_path("geographies")
if (!dir.exists(geo_base_path)) dir.create(geo_base_path)
@@ -56,6 +56,14 @@ get_statcan_geographies <- function(census_year,level,type="cartographic",
utils::download.file(url,tmp,mode="wb",quiet=quiet)
options(timeout = old_timeout)
utils::unzip(tmp,exdir = exdir)
+ fs <- dir(exdir,full.names = TRUE)
+ if (length(fs)==1 && dir.exists(fs)) {
+ tmp_dir <- file.path(geo_base_path,"XXXX")
+ file.rename(exdir,tmp_dir)
+ fs <- dir(tmp_dir,full.names = TRUE)
+ file.rename(fs,exdir)
+ unlink(tmp_dir)
+ }
} else {
if (!quiet) message("Reading geographic data from local cache.")
}
diff --git a/R/helpers.R b/R/helpers.R
index a46ddd0f..35385b89 100644
--- a/R/helpers.R
+++ b/R/helpers.R
@@ -22,7 +22,10 @@ cache_path <- function(...) {
if (nchar(cache_dir)==0) {
if (!is.null(getOption("cancensus.cache_path"))) {
cache_dir <- getOption("cancensus.cache_path")
- } else cache_dir <- tempdir()
+ } else {
+ cache_dir <- tempdir()
+ message(cm_no_cache_path_message)
+ }
}
if (!is.character(cache_dir)) {
stop("Corrupt 'CM_CACHE_PATH' environment variable or 'cancensus.cache_path' option. Must be a path.",
diff --git a/R/user_settings.R b/R/user_settings.R
index 3febf2ff..3278a78c 100644
--- a/R/user_settings.R
+++ b/R/user_settings.R
@@ -43,7 +43,8 @@ set_cancensus_api_key <- function(key, overwrite = FALSE, install = FALSE){
keyconcat <- paste0("CM_API_KEY='", key, "'")
# Append API key to .Renviron file
write(keyconcat, renv, sep = "\n", append = TRUE)
- message('Your API key has been stored in your .Renviron and can be accessed by Sys.getenv("CM_API_KEY"). \nTo use now, restart R or run `readRenviron("~/.Renviron")`')
+ Sys.setenv(CM_API_KEY = key)
+ message('Your API key has been stored in your .Renviron and can be accessed by Sys.getenv("CM_API_KEY").')
} else {
message("API key set for duration of session. To install your API key for use across sessions, run this function with `install = TRUE`.")
Sys.setenv(CM_API_KEY = key)
@@ -65,7 +66,7 @@ set_cancensus_api_key <- function(key, overwrite = FALSE, install = FALSE){
#'\dontrun{
#' set_cancensus_cache_path("~/cancensus_cache")
#'
-#' # This will set the cache path permanently until ovewritten again
+#' # This will set the cache path permanently until overwritten again
#' set_cancensus_cache_path("~/cancensus_cache", install = TRUE)
#' }
set_cancensus_cache_path <- function(cache_path, overwrite = FALSE, install = FALSE){
@@ -93,7 +94,8 @@ set_cancensus_cache_path <- function(cache_path, overwrite = FALSE, install = FA
keyconcat <- paste0("CM_CACHE_PATH='", cache_path, "'")
# Append cache path .Renviron file
write(keyconcat, renv, sep = "\n", append = TRUE)
- message('Your cache path has been stored in your .Renviron and can be accessed by Sys.getenv("CM_CACHE_PATH"). \nTo use now, restart R or run readRenviron("~/.Renviron").')
+ message('Your cache path has been stored in your .Renviron and can be accessed by Sys.getenv("CM_CACHE_PATH").')
+ Sys.setenv('CM_CACHE_PATH' = cache_path)
} else {
message("Cache set for duration of session. To permanently add your cache path for use across sessions, run this function with install = TRUE.")
Sys.setenv('CM_CACHE_PATH' = cache_path)
@@ -138,9 +140,8 @@ show_cancensus_cache_path <- function() {
cm_no_cache_path_message <- paste(
"Census data is currently stored temporarily.\n\n",
"In order to speed up performance, reduce API quota usage, and reduce",
- "unnecessary network calls, please set up a persistent cache directory by",
- "setting the environment variable CM_CACHE_PATH= 'Page not found (404)
diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html
index edbf629d..a1be5b1e 100644
--- a/docs/LICENSE-text.html
+++ b/docs/LICENSE-text.html
@@ -23,7 +23,7 @@
@@ -103,7 +103,7 @@ License
diff --git a/docs/articles/Dwellings_by_document_type_cross_tabulation.html b/docs/articles/Dwellings_by_document_type_cross_tabulation.html
index 21ac4288..09d9b034 100644
--- a/docs/articles/Dwellings_by_document_type_cross_tabulation.html
+++ b/docs/articles/Dwellings_by_document_type_cross_tabulation.html
@@ -51,7 +51,7 @@
@@ -180,10 +180,10 @@ E
started with cancensus vignette.
# Attribution for the dataset to be used in graphs
-attribution <- dataset_attribution("CA16xSD")
+attribution <- dataset_attribution("CA16xSD")
# Select all variables base variables, this gives us total counts by structural type of dwelling
-vars <- list_census_vectors("CA16xSD") %>%
+vars <- list_census_vectors("CA16xSD") %>%
filter(is.na(parent_vector))
variables <- setNames(vars$vector,vars$label)
@@ -213,7 +213,7 @@ E
dwelling_types <- setdiff(names(variables),"Total dwellings")
# Grab the census data and compute shares for each dwelling type
-census_data <- get_census("CA16xSD",regions=list(CSD="3520005"), vectors = variables, quiet = TRUE) %>%
+census_data <- get_census("CA16xSD",regions=list(CSD="3520005"), vectors = variables, quiet = TRUE) %>%
pivot_longer(cols = all_of(dwelling_types)) %>%
mutate(share=value/`Total dwellings`)
To visualize what this looks like on a bar chart:
@@ -228,7 +228,7 @@As with regular Census data, all data can be retrieved as spatial
data. Sometimes it’s easier to use the CensusMapper API interface to
search for and select the variables we are interested in. The
-explore_census_vectors()
function opens a browser with the
+explore_census_vectors()
function opens a browser with the
variable selection tool, we determine that “v_CA16xSD_1” and
“v_CA16xSD_28” are the variables enumerating all dwellings and all
unoccupied dwellings, respectively.
Adding colour ramps and additional interactivity takes a little bit +
+Adding colour ramps and additional interactivity takes a little bit more work but is still pretty easy to implement. Following this example we can specify the colour ramp to match our needs.
@@ -242,8 +242,8 @@Interactive maps with leaflet= 1, opacity = 1, fillOpacity = 0.65)
Site built with pkgdown 2.0.6.
+Site built with pkgdown 2.0.7.
diff --git a/docs/articles/Making_maps_with_cancensus_files/figure-html/unnamed-chunk-4-1.png b/docs/articles/Making_maps_with_cancensus_files/figure-html/unnamed-chunk-4-1.png index c9afb25a..0667972c 100644 Binary files a/docs/articles/Making_maps_with_cancensus_files/figure-html/unnamed-chunk-4-1.png and b/docs/articles/Making_maps_with_cancensus_files/figure-html/unnamed-chunk-4-1.png differ diff --git a/docs/articles/Making_maps_with_cancensus_files/htmlwidgets-1.5.4/htmlwidgets.js b/docs/articles/Making_maps_with_cancensus_files/htmlwidgets-1.6.2/htmlwidgets.js similarity index 96% rename from docs/articles/Making_maps_with_cancensus_files/htmlwidgets-1.5.4/htmlwidgets.js rename to docs/articles/Making_maps_with_cancensus_files/htmlwidgets-1.6.2/htmlwidgets.js index da8b2367..1067d029 100644 --- a/docs/articles/Making_maps_with_cancensus_files/htmlwidgets-1.5.4/htmlwidgets.js +++ b/docs/articles/Making_maps_with_cancensus_files/htmlwidgets-1.6.2/htmlwidgets.js @@ -287,20 +287,18 @@ document.body.style.height = "100%"; document.documentElement.style.width = "100%"; document.documentElement.style.height = "100%"; - if (cel) { - cel.style.position = "absolute"; - var pad = unpackPadding(sizing.padding); - cel.style.top = pad.top + "px"; - cel.style.right = pad.right + "px"; - cel.style.bottom = pad.bottom + "px"; - cel.style.left = pad.left + "px"; - el.style.width = "100%"; - el.style.height = "100%"; - } + cel.style.position = "absolute"; + var pad = unpackPadding(sizing.padding); + cel.style.top = pad.top + "px"; + cel.style.right = pad.right + "px"; + cel.style.bottom = pad.bottom + "px"; + cel.style.left = pad.left + "px"; + el.style.width = "100%"; + el.style.height = "100%"; return { - getWidth: function() { return cel.offsetWidth; }, - getHeight: function() { return cel.offsetHeight; } + getWidth: function() { return cel.getBoundingClientRect().width; }, + getHeight: function() { return cel.getBoundingClientRect().height; } }; } else { @@ -308,8 +306,8 @@ el.style.height = px(sizing.height); return { - getWidth: function() { return el.offsetWidth; }, - getHeight: function() { return el.offsetHeight; } + getWidth: function() { return cel.getBoundingClientRect().width; }, + getHeight: function() { return cel.getBoundingClientRect().height; } }; } } @@ -533,8 +531,8 @@ elementData(el, "initialized", true); if (bindingDef.initialize) { - var result = bindingDef.initialize(el, el.offsetWidth, - el.offsetHeight); + var rect = el.getBoundingClientRect(); + var result = bindingDef.initialize(el, rect.width, rect.height); elementData(el, "init_result", result); } } @@ -576,29 +574,30 @@ forEach(matches, function(el) { var sizeObj = initSizing(el, binding); + var getSize = function(el) { + if (sizeObj) { + return {w: sizeObj.getWidth(), h: sizeObj.getHeight()} + } else { + var rect = el.getBoundingClientRect(); + return {w: rect.width, h: rect.height} + } + }; + if (hasClass(el, "html-widget-static-bound")) return; el.className = el.className + " html-widget-static-bound"; var initResult; if (binding.initialize) { - initResult = binding.initialize(el, - sizeObj ? sizeObj.getWidth() : el.offsetWidth, - sizeObj ? sizeObj.getHeight() : el.offsetHeight - ); + var size = getSize(el); + initResult = binding.initialize(el, size.w, size.h); elementData(el, "init_result", initResult); } if (binding.resize) { - var lastSize = { - w: sizeObj ? sizeObj.getWidth() : el.offsetWidth, - h: sizeObj ? sizeObj.getHeight() : el.offsetHeight - }; + var lastSize = getSize(el); var resizeHandler = function(e) { - var size = { - w: sizeObj ? sizeObj.getWidth() : el.offsetWidth, - h: sizeObj ? sizeObj.getHeight() : el.offsetHeight - }; + var size = getSize(el); if (size.w === 0 && size.h === 0) return; if (size.w === lastSize.w && size.h === lastSize.h) @@ -900,4 +899,3 @@ return result; } })(); - diff --git a/docs/articles/Making_maps_with_cancensus_files/leaflet-binding-2.1.1/leaflet.js b/docs/articles/Making_maps_with_cancensus_files/leaflet-binding-2.2.0/leaflet.js similarity index 99% rename from docs/articles/Making_maps_with_cancensus_files/leaflet-binding-2.1.1/leaflet.js rename to docs/articles/Making_maps_with_cancensus_files/leaflet-binding-2.2.0/leaflet.js index 1eafcbe0..c8e7e5e0 100644 --- a/docs/articles/Making_maps_with_cancensus_files/leaflet-binding-2.1.1/leaflet.js +++ b/docs/articles/Making_maps_with_cancensus_files/leaflet-binding-2.2.0/leaflet.js @@ -593,8 +593,20 @@ function preventUnintendedZoomOnScroll(map) { }); (0, _jquery2["default"])(document).on("mousemove", "*", function (e) { // Did the mouse really move? - if (lastScreen.x !== null && e.screenX !== lastScreen.x || e.screenY !== lastScreen.y) { - // It really moved. Enable zooming. + if (map.options.scrollWheelZoom) { + if (lastScreen.x !== null && e.screenX !== lastScreen.x || e.screenY !== lastScreen.y) { + // It really moved. Enable zooming. + map.scrollWheelZoom.enable(); + lastScreen = { + x: null, + y: null + }; + } + } + }); + (0, _jquery2["default"])(document).on("mousedown", ".leaflet", function (e) { + // Clicking always enables zooming. + if (map.options.scrollWheelZoom) { map.scrollWheelZoom.enable(); lastScreen = { x: null, @@ -602,14 +614,6 @@ function preventUnintendedZoomOnScroll(map) { }; } }); - (0, _jquery2["default"])(document).on("mousedown", ".leaflet", function (e) { - // Clicking always enables zooming. - map.scrollWheelZoom.enable(); - lastScreen = { - x: null, - y: null - }; - }); } _htmlwidgets2["default"].widget({ diff --git a/docs/articles/Making_maps_with_cancensus_files/leaflet-providers-1.9.0/leaflet-providers_1.9.0.js b/docs/articles/Making_maps_with_cancensus_files/leaflet-providers-1.13.0/leaflet-providers_1.13.0.js similarity index 64% rename from docs/articles/Making_maps_with_cancensus_files/leaflet-providers-1.9.0/leaflet-providers_1.9.0.js rename to docs/articles/Making_maps_with_cancensus_files/leaflet-providers-1.13.0/leaflet-providers_1.13.0.js index e842c82d..e9986a97 100644 --- a/docs/articles/Making_maps_with_cancensus_files/leaflet-providers-1.9.0/leaflet-providers_1.9.0.js +++ b/docs/articles/Making_maps_with_cancensus_files/leaflet-providers-1.13.0/leaflet-providers_1.13.0.js @@ -77,7 +77,7 @@ L.TileLayer.Provider.providers = { OpenStreetMap: { - url: '//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', + url: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', options: { maxZoom: 19, attribution: @@ -86,27 +86,27 @@ variants: { Mapnik: {}, DE: { - url: '//{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png', + url: 'https://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png', options: { maxZoom: 18 } }, CH: { - url: '//tile.osm.ch/switzerland/{z}/{x}/{y}.png', + url: 'https://tile.osm.ch/switzerland/{z}/{x}/{y}.png', options: { maxZoom: 18, bounds: [[45, 5], [48, 11]] } }, France: { - url: '//{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png', + url: 'https://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png', options: { maxZoom: 20, - attribution: '© Openstreetmap France | {attribution.OpenStreetMap}' + attribution: '© OpenStreetMap France | {attribution.OpenStreetMap}' } }, HOT: { - url: '//{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', + url: 'https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', options: { attribution: '{attribution.OpenStreetMap}, ' + @@ -115,7 +115,7 @@ } }, BZH: { - url: '//tile.openstreetmap.bzh/br/{z}/{x}/{y}.png', + url: 'https://tile.openstreetmap.bzh/br/{z}/{x}/{y}.png', options: { attribution: '{attribution.OpenStreetMap}, Tiles courtesy of Breton OpenStreetMap Team', bounds: [[46.2, -5.5], [50, 0.7]] @@ -124,16 +124,16 @@ } }, OpenSeaMap: { - url: '//tiles.openseamap.org/seamark/{z}/{x}/{y}.png', + url: 'https://tiles.openseamap.org/seamark/{z}/{x}/{y}.png', options: { attribution: 'Map data: © OpenSeaMap contributors' } }, - OpenPtMap: { - url: 'http://openptmap.org/tiles/{z}/{x}/{y}.png', + OPNVKarte: { + url: 'https://tileserver.memomaps.de/tilegen/{z}/{x}/{y}.png', options: { - maxZoom: 17, - attribution: 'Map data: © OpenPtMap contributors' + maxZoom: 18, + attribution: 'Map memomaps.de CC-BY-SA, map data {attribution.OpenStreetMap}' } }, OpenTopoMap: { @@ -158,12 +158,33 @@ } }, SafeCast: { - url: '//s3.amazonaws.com/te512.safecast.org/{z}/{x}/{y}.png', + url: 'https://s3.amazonaws.com/te512.safecast.org/{z}/{x}/{y}.png', options: { maxZoom: 16, attribution: 'Map data: {attribution.OpenStreetMap} | Map style: © SafeCast (CC-BY-SA)' } }, + Stadia: { + url: 'https://tiles.stadiamaps.com/tiles/alidade_smooth/{z}/{x}/{y}{r}.png', + options: { + maxZoom: 20, + attribution: '© Stadia Maps, © OpenMapTiles © OpenStreetMap contributors' + }, + variants: { + AlidadeSmooth: { + url: 'https://tiles.stadiamaps.com/tiles/alidade_smooth/{z}/{x}/{y}{r}.png' + }, + AlidadeSmoothDark: { + url: 'https://tiles.stadiamaps.com/tiles/alidade_smooth_dark/{z}/{x}/{y}{r}.png' + }, + OSMBright: { + url: 'https://tiles.stadiamaps.com/tiles/osm_bright/{z}/{x}/{y}{r}.png' + }, + Outdoors: { + url: 'https://tiles.stadiamaps.com/tiles/outdoors/{z}/{x}/{y}{r}.png' + } + } + }, Thunderforest: { url: 'https://{s}.tile.thunderforest.com/{variant}/{z}/{x}/{y}.png?apikey={apikey}', options: { @@ -197,60 +218,17 @@ Neighbourhood: 'neighbourhood' } }, - OpenMapSurfer: { - url: 'https://maps.heigit.org/openmapsurfer/tiles/{variant}/webmercator/{z}/{x}/{y}.png', + CyclOSM: { + url: 'https://{s}.tile-cyclosm.openstreetmap.fr/cyclosm/{z}/{x}/{y}.png', options: { - maxZoom: 19, - variant: 'roads', - attribution: 'Imagery from GIScience Research Group @ University of Heidelberg | Map data ' - }, - variants: { - Roads: { - options: { - variant: 'roads', - attribution: '{attribution.OpenMapSurfer}{attribution.OpenStreetMap}' - } - }, - Hybrid: { - options: { - variant: 'hybrid', - attribution: '{attribution.OpenMapSurfer}{attribution.OpenStreetMap}' - } - }, - AdminBounds: { - options: { - variant: 'adminb', - maxZoom: 18, - attribution: '{attribution.OpenMapSurfer}{attribution.OpenStreetMap}' - } - }, - ContourLines: { - options: { - variant: 'asterc', - maxZoom: 18, - minZoom: 13, - attribution: '{attribution.OpenMapSurfer} ASTER GDEM' - } - }, - Hillshade: { - options: { - variant: 'asterh', - maxZoom: 18, - attribution: '{attribution.OpenMapSurfer} ASTER GDEM, SRTM' - } - }, - ElementsAtRisk: { - options: { - variant: 'elements_at_risk', - attribution: '{attribution.OpenMapSurfer}{attribution.OpenStreetMap}' - } - } + maxZoom: 20, + attribution: 'CyclOSM | Map data: {attribution.OpenStreetMap}' } }, Hydda: { - url: '//{s}.tile.openstreetmap.se/hydda/{variant}/{z}/{x}/{y}.png', + url: 'https://{s}.tile.openstreetmap.se/hydda/{variant}/{z}/{x}/{y}.png', options: { - maxZoom: 18, + maxZoom: 20, variant: 'full', attribution: 'Tiles courtesy of OpenStreetMap Sweden — Map data {attribution.OpenStreetMap}' }, @@ -260,20 +238,75 @@ RoadsAndLabels: 'roads_and_labels' } }, + Jawg: { + url: 'https://{s}.tile.jawg.io/{variant}/{z}/{x}/{y}{r}.png?access-token={accessToken}', + options: { + attribution: + '© JawgMaps ' + + '{attribution.OpenStreetMap}', + minZoom: 0, + maxZoom: 22, + subdomains: 'abcd', + variant: 'jawg-terrain', + // Get your own Jawg access token here : https://www.jawg.io/lab/ + // NB : this is a demonstration key that comes with no guarantee + accessToken: 'To see all available T1FF datasets and their reference codes we can
-use list_census_datasets()
.
list_census_datasets()
.
-list_census_datasets() %>%
+list_census_datasets() %>%
filter(grepl("taxfiler",description))
#> # A tibble: 19 × 6
-#> dataset description geo_dataset attribution refer…¹ refer…²
-#> <chr> <chr> <chr> <chr> <chr> <chr>
-#> 1 TX2000 2000 T1FF taxfiler data CA1996 StatCan 2000 T1F… 72-212… https:…
-#> 2 TX2001 2001 T1FF taxfiler data CA01 StatCan 2001 T1F… 72-212… https:…
-#> 3 TX2002 2002 T1FF taxfiler data CA01 StatCan 2002 T1F… 72-212… https:…
-#> 4 TX2003 2003 T1FF taxfiler data CA01 StatCan 2003 T1F… 72-212… https:…
-#> 5 TX2004 2004 T1FF taxfiler data CA01 StatCan 2004 T1F… 72-212… https:…
-#> 6 TX2005 2005 T1FF taxfiler data CA01 StatCan 2005 T1F… 72-212… https:…
-#> 7 TX2006 2006 T1FF taxfiler data CA06 StatCan 2006 T1F… 72-212… https:…
-#> 8 TX2007 2007 T1FF taxfiler data CA06 StatCan 2007 T1F… 72-212… https:…
-#> 9 TX2008 2008 T1FF taxfiler data CA06 StatCan 2008 T1F… 72-212… https:…
-#> 10 TX2009 2009 T1FF taxfiler data CA06 StatCan 2009 T1F… 72-212… https:…
-#> 11 TX2010 2010 T1FF taxfiler data CA06 StatCan 2010 T1F… 72-212… https:…
-#> 12 TX2011 2011 T1FF taxfiler data CA06 StatCan 2011 T1F… 72-212… https:…
-#> 13 TX2012 2012 T1FF taxfiler data CA11 StatCan 2012 T1F… 72-212… https:…
-#> 14 TX2013 2013 T1FF taxfiler data CA11 StatCan 2013 T1F… 72-212… https:…
-#> 15 TX2014 2014 T1FF taxfiler data CA11 StatCan 2014 T1F… 72-212… https:…
-#> 16 TX2015 2015 T1FF taxfiler data CA11 StatCan 2015 T1F… 72-212… https:…
-#> 17 TX2016 2016 T1FF taxfiler data CA16 StatCan 2016 T1F… 72-212… https:…
-#> 18 TX2017 2017 T1FF taxfiler data CA16 StatCan 2017 T1F… 72-212… https:…
-#> 19 TX2018 2018 T1FF taxfiler data CA16 StatCan 2018 T1F… 72-212… https:…
-#> # … with abbreviated variable names ¹reference, ²reference_url
And, as an example, available data vectors for one such T1FF dataset.
-list_census_vectors('TX2017')
+list_census_vectors('TX2017')
#> # A tibble: 818 × 7
-#> vector type label units parent…¹ aggre…² details
-#> <chr> <fct> <chr> <fct> <chr> <chr> <chr>
-#> 1 v_TX2017_1 Total Taxfilers - # Number NA Additi… Tax da…
-#> 2 v_TX2017_3 Total % 0-24 Percentage (0-100) v_TX201… Averag… Tax da…
-#> 3 v_TX2017_4 Total % 25-44 Percentage (0-100) v_TX201… Averag… Tax da…
-#> 4 v_TX2017_5 Total % 45-64 Percentage (0-100) v_TX201… Averag… Tax da…
-#> 5 v_TX2017_6 Total % 65+ Percentage (0-100) v_TX201… Averag… Tax da…
-#> 6 v_TX2017_7 Total Average - Age Ratio v_TX201… Averag… Tax da…
-#> 7 v_TX2017_8 Total % female Percentage (0-100) v_TX201… Averag… Tax da…
-#> 8 v_TX2017_9 Total % married Percentage (0-100) v_TX201… Averag… Tax da…
-#> 9 v_TX2017_10 Total % in appt Percentage (0-100) v_TX201… Averag… Tax da…
-#> 10 v_TX2017_11 Total All persons - # Number NA Additi… Tax da…
-#> # … with 808 more rows, and abbreviated variable names ¹parent_vector,
-#> # ²aggregation
This particular dataset has over 800 individual vectors. The vector
codes follow a regular pattern across different years, and we can use
this to quickly identify all the relevant variables of interest across
multiple datasets. We can utilized the CensusMapper
graphical variable selection interface, which can also be reached by
-calling Here we also re-organized the data by year. All that’s left is to
plot the data, one year at a time. Analyzing change over longer timelines that span changes in Census
geometries involves more work, the tongfen
@@ -311,7 +309,7 @@ Site built with pkgdown 2.0.6. Site built with pkgdown 2.0.7. Alternatively, the latest development version can be installed from
-Github using explore_census_vectors()
from the R console. For
+calling explore_census_vectors()
from the R console. For
this example we are interested in low income families and note that the
internal CensusMapper vector for all families is of the form
*v_TX
years <- c(2006,2011,2014,2018)
# Attribution for the dataset to be used in graphs
-attribution <- dataset_attribution(paste0("TX",years))
+attribution <- dataset_attribution(paste0("TX",years))
plot_data <- years %>%
lapply(function(year) {
@@ -245,12 +243,12 @@
vectors <- c("Families"=paste0("v_",dataset,"_607"),
"CFLIM-AT"=paste0("v_",dataset,"_786"))
- get_census(dataset,regions=list(CMA="59933"),vectors = vectors,
+ get_census(dataset,regions=list(CMA="59933"),vectors = vectors,
geo_format = 'sf', level="CT", quiet = TRUE) %>%
select(c("GeoUID",names(vectors))) %>%
mutate(Year=year)
}) %>%
- bind_rows() %>%
+ bind_rows() %>%
mutate(share=`CFLIM-AT`/Families)
scale_fill_gradient2(labels=scales::percent) +
#scale_fill_viridis_c(labels=scales::percent,option = "inferno") +
coord_sf(datum=NA,xlim=c(-123.4, -122.5), ylim=c(49.01, 49.4)) +
- labs(title="Change in share of census families in low income 2006-2011",fill="Percentage\npoint change",caption=dataset_attribution(paste0("TX",c(2006,2011))))
+ labs(title="Change in share of census families in low income 2006-2011",fill="Percentage\npoint change",caption=dataset_attribution(paste0("TX",c(2006,2011))))
-Cancensus and CensusMappercancensus, to provide interactive geographic
visualizations of Canadian Census data. CensusMapper databases store all
publicly available data from Statistics Canada for the 2006, 2011, and
-2016 Censuses. Censusmapper data can be accessed via an API and
+2016 Censuses. CensusMapper data can be accessed via an API and
cancensus is built to interface directly with it.
API Key
@@ -161,7 +161,7 @@
API Key
the CensusMapper menu bar). Once you have your key, you can store it in
your system environment so it is automatically used in API calls. To do
so just enter
-
set_api_key(<your_api_key>, install = TRUE)
+set_cancensus_api_key(<your_api_key>', install = TRUE)
Installing cancensus
@@ -171,31 +171,29 @@
Installing cancensus
install.packages("cancensus")
-library(cancensus)
-
-options(cancensus.api_key = "your_api_key")
-options(cancensus.cache_path = "custom cache path")
devtools
.
# install.packages("devtools")
-devtools::install_github("mountainmath/cancensus")
+remotes::install_github("mountainmath/cancensus")
library(cancensus)
options(cancensus.api_key = "your_api_key")
options(cancensus.cache_path = "custom cache path")
For performance reasons, and to avoid unnecessarily drawing down API
-quotas, cancensus caches data queries under the hood.
-By default, cancensus caches in R’s temporary
-directory, but this cache is not persistent across sessions. In order to
-speed up performance, reduce quota usage, and reduce the need for
-unnecessary network calls, we recommend assigning a persistent local
-cache using
-set_cache_path(<local cache path>, install = TRUE)
,
-this enables more efficient loading and reuse of downloaded data.. Users
-will be prompted with a suggestion to change their default cache
-location when making API calls if one has not been set yet.
If you have not already done so, you can install the API keys and the +data cache path. You can get your free API key when you sign up for a CensusMapper account and check your +profile. Additionally we recommend you set a permanent data cache path +so that census data you query is stored persistently across +sessions.
+
+# Only need to install api key can cache path once
+set_cancensus_api_key('<your_api_key>', install = TRUE)
+set_cancensus_cache_path('<local cache path>', install = TRUE)
Data in the persistent cache can be managed via the functions
+list_cancensus_cache
and
+remove_from_cancensus_cache
if needed.
sf
to return
an sf-class data frame, or sp
to return a
SpatialPolygonsDataFrame object.
-++# Returns a data frame with data only -census_data <- get_census(dataset='CA21', regions=list(CMA="59933"), +census_data <- get_census(dataset='CA21', regions=list(CMA="59933"), vectors=c("v_CA21_434","v_CA21_435","v_CA21_440"), level='CSD', use_cache = FALSE, geo_format = NA, quiet = TRUE) # Returns data and geography as an sf-class data frame -census_data <- get_census(dataset='CA21', regions=list(CMA="59933"), +census_data <- get_census(dataset='CA21', regions=list(CMA="59933"), vectors=c("v_CA21_434","v_CA21_435","v_CA21_440"), level='CSD', use_cache = FALSE, geo_format = 'sf', quiet = TRUE) # Returns a SpatialPolygonsDataFrame object with data and geography -census_data <- get_census(dataset='CA21', regions=list(CMA="59933"), +census_data <- get_census(dataset='CA21', regions=list(CMA="59933"), vectors=c("v_CA21_434","v_CA21_435","v_CA21_440"), level='CSD', use_cache = FALSE, geo_format = 'sp', quiet = TRUE)
cancensus utilizes caching to increase speed, @@ -236,7 +234,7 @@
Accessing Census Datause_cache = FALSE as a parameter for
get_census
.Additional parameters for advanced options can be viewed by running -
+?get_census
.?get_census
.Census Datasets
@@ -244,7 +242,7 @@Census Datasetslist_census_datasets to check what datasets are currently available for access through the CensusMapper API. Additional data for -the 2016 Census will be included in Censusmapper within a day or two +the 2016 Census will be included in CensusMapper within a day or two after public release by Statistics Canada. Statistics Canada maintains a release schedule for the Census 2016 Program which can be viewed on their website. @@ -257,28 +255,27 @@
Census Datasets -
The function
list_census_datasets()
will show all +The function
-list_census_datasets()
will show all available datasets alongside their metadata.-list_census_datasets() +
+#> dataset description geo_dataset attribution reference reference_url +#> <chr> <chr> <chr> <chr> <chr> <chr> +#> 1 CA1996 1996 Canada Census CA1996 StatCan 19… 92-351-U https://www1… +#> 2 CA01 2001 Canada Census CA01 StatCan 20… 92-378-X https://www1… +#> 3 CA06 2006 Canada Census CA06 StatCan 20… 92-566-X https://www1… +#> 4 CA11 2011 Canada Census a… CA11 StatCan 20… 98-301-X… https://www1… +#> 5 CA16 2016 Canada Census CA16 StatCan 20… 98-301-X https://www1… +#> 6 CA21 2021 Canada Census CA21 StatCan 20… 98-301-X https://www1… +#> 7 CA01xSD 2001 Canada Census x… CA01 StatCan 20… 92-378-X https://www1… +#> 8 CA06xSD 2006 Canada Census x… CA06 StatCan 20… 92-566-X https://www1… +#> 9 CA11xSD 2011 Canada Census x… CA11 StatCan 20… 98-301-X https://www1… +#> 10 CA16xSD 2016 Canada Census x… CA16 StatCan 20… 98-301-X https://www1… +#> # ℹ 19 more rows+list_census_datasets() #> # A tibble: 29 × 6 -#> dataset description geo_d…¹ attri…² refer…³ refer…⁴ -#> <chr> <chr> <chr> <chr> <chr> <chr> -#> 1 CA1996 1996 Canada Census CA1996 StatCa… 92-351… https:… -#> 2 CA01 2001 Canada Census CA01 StatCa… 92-378… https:… -#> 3 CA06 2006 Canada Census CA06 StatCa… 92-566… https:… -#> 4 CA11 2011 Canada Census and NHS CA11 StatCa… 98-301… https:… -#> 5 CA16 2016 Canada Census CA16 StatCa… 98-301… https:… -#> 6 CA21 2021 Canada Census CA21 StatCa… 98-301… https:… -#> 7 CA01xSD 2001 Canada Census xtab - Structural… CA01 StatCa… 92-378… https:… -#> 8 CA06xSD 2006 Canada Census xtab - Structural… CA06 StatCa… 92-566… https:… -#> 9 CA11xSD 2011 Canada Census xtab - Structural… CA11 StatCa… 98-301… https:… -#> 10 CA16xSD 2016 Canada Census xtab - Structural… CA16 StatCa… 98-301… https:… -#> # … with 19 more rows, and abbreviated variable names ¹geo_dataset, -#> # ²attribution, ³reference, ⁴reference_url
As other Census datasets become available via the CensusMapper API, they will be listed as output when calling -
+list_census_datasets()
.list_census_datasets()
.Census Regions @@ -292,29 +289,29 @@
Census Regionscancensus provides a function,
list_census_regions(dataset)
, to display all named census regions and their corresponding id for a given census dataset. --list_census_regions("CA21") +
+#> region name level pop municipal_status CMA_UID CD_UID PR_UID +#> <chr> <chr> <chr> <int> <chr> <chr> <chr> <chr> +#> 1 01 Canada C 3.70e7 NA NA NA NA +#> 2 35 Ontario PR 1.42e7 Ont. NA NA NA +#> 3 24 Quebec PR 8.50e6 Que. NA NA NA +#> 4 59 British Columbia PR 5.00e6 B.C. NA NA NA +#> 5 48 Alberta PR 4.26e6 Alta. NA NA NA +#> 6 46 Manitoba PR 1.34e6 Man. NA NA NA +#> 7 47 Saskatchewan PR 1.13e6 Sask. NA NA NA +#> 8 12 Nova Scotia PR 9.69e5 N.S. NA NA NA +#> 9 13 New Brunswick PR 7.76e5 N.B. NA NA NA +#> 10 10 Newfoundland and … PR 5.11e5 N.L. NA NA NA +#> # ℹ 5,508 more rows+list_census_regions("CA21") #> # A tibble: 5,518 × 8 -#> region name level pop munic…¹ CMA_UID CD_UID PR_UID -#> <chr> <chr> <chr> <int> <chr> <chr> <chr> <chr> -#> 1 01 Canada C 36991981 NA NA NA NA -#> 2 35 Ontario PR 14223942 Ont. NA NA NA -#> 3 24 Quebec PR 8501833 Que. NA NA NA -#> 4 59 British Columbia PR 5000879 B.C. NA NA NA -#> 5 48 Alberta PR 4262635 Alta. NA NA NA -#> 6 46 Manitoba PR 1342153 Man. NA NA NA -#> 7 47 Saskatchewan PR 1132505 Sask. NA NA NA -#> 8 12 Nova Scotia PR 969383 N.S. NA NA NA -#> 9 13 New Brunswick PR 775610 N.B. NA NA NA -#> 10 10 Newfoundland and Labrador PR 510550 N.L. NA NA NA -#> # … with 5,508 more rows, and abbreviated variable name ¹municipal_status
The
-regions
parameter inget_census
requires as input a list of region id strings that correspond to that regions geoid. You can combine different regions together into region lists.@@ -422,23 +419,22 @@+# Retrieves Vancouver and Toronto -list_census_regions('CA21') %>% +list_census_regions('CA21') %>% filter(level == "CMA", name %in% c("Vancouver","Toronto")) #> # A tibble: 2 × 8 #> region name level pop municipal_status CMA_UID CD_UID PR_UID @@ -322,7 +319,7 @@
Census Regions#> 1 35535 Toronto CMA 6202225 B NA NA 35 #> 2 59933 Vancouver CMA 2642825 B NA NA 59 -census_data <- get_census(dataset='CA21', regions=list(CMA=c("59933","35535")), +census_data <- get_census(dataset='CA21', regions=list(CMA=c("59933","35535")), vectors=c("v_CA21_434","v_CA21_435","v_CA21_440"), level='CSD', use_cache = FALSE, quiet = TRUE)
Displaying available Census varia
Run
-list_census_vectors(dataset)
to view all available Census variables for a given dataset.-list_census_vectors("CA21") +
+#> vector type label units parent_vector aggregation details +#> <chr> <fct> <chr> <fct> <chr> <chr> <chr> +#> 1 v_CA21_1 Total Population, 2021 Numb… NA Additive CA 202… +#> 2 v_CA21_2 Total Population, 2016 Numb… NA Additive CA 202… +#> 3 v_CA21_3 Total Population percenta… Numb… NA Average of… CA 202… +#> 4 v_CA21_4 Total Total private dwell… Numb… NA Additive CA 202… +#> 5 v_CA21_5 Total Private dwellings o… Numb… v_CA21_4 Additive CA 202… +#> 6 v_CA21_6 Total Population density … Ratio NA Average of… CA 202… +#> 7 v_CA21_7 Total Land area in square… Numb… NA Additive CA 202… +#> 8 v_CA21_8 Total Total - Age Numb… NA Additive CA 202… +#> 9 v_CA21_9 Male Total - Age Numb… NA Additive CA 202… +#> 10 v_CA21_10 Female Total - Age Numb… NA Additive CA 202… +#> # ℹ 7,699 more rows+list_census_vectors("CA21") #> # A tibble: 7,709 × 7 -#> vector type label units paren…¹ aggre…² details -#> <chr> <fct> <chr> <fct> <chr> <chr> <chr> -#> 1 v_CA21_1 Total Population, 2021 Numb… NA Additi… CA 202… -#> 2 v_CA21_2 Total Population, 2016 Numb… NA Additi… CA 202… -#> 3 v_CA21_3 Total Population percentage change,… Numb… NA Averag… CA 202… -#> 4 v_CA21_4 Total Total private dwellings Numb… NA Additi… CA 202… -#> 5 v_CA21_5 Total Private dwellings occupied by… Numb… v_CA21… Additi… CA 202… -#> 6 v_CA21_6 Total Population density per square… Ratio NA Averag… CA 202… -#> 7 v_CA21_7 Total Land area in square kilometres Numb… NA Additi… CA 202… -#> 8 v_CA21_8 Total Total - Age Numb… NA Additi… CA 202… -#> 9 v_CA21_9 Male Total - Age Numb… NA Additi… CA 202… -#> 10 v_CA21_10 Female Total - Age Numb… NA Additi… CA 202… -#> # … with 7,699 more rows, and abbreviated variable names ¹parent_vector, -#> # ²aggregation
Variable characteristics @@ -468,7 +464,7 @@
Variable search
Each Census dataset features numerous variables making it a bit of a challenge to find the exact variable you are looking for. There is a -function,
find_census_vectors()
, for searching through +function,find_census_vectors()
, for searching through Census variable metadata in a few different ways. There are three types of searches possible using this function: exact search, which simply looks for exact string matches for a given query against the vector @@ -478,22 +474,22 @@Variable searchquery_type argument when calling
find_census_variables()
function. -@@ -148,23 +148,22 @@+# Find the variable indicating the number of people of Austrian ethnic origin -find_census_vectors("Australia", dataset = "CA16", type = "total", query_type = "exact") +find_census_vectors("Australia", dataset = "CA16", type = "total", query_type = "exact") #> # A tibble: 2 × 4 #> vector type label details #> <chr> <fct> <chr> <chr> #> 1 v_CA16_3813 Total Australia 25% Data; Citizenship and Immigration; Total - S… #> 2 v_CA16_4809 Total Australian 25% Data; Minority / Origin; Total - Ethnic orig… -find_census_vectors("Australia origin", dataset = "CA16", type = "total", query_type = "semantic") +find_census_vectors("Australia origin", dataset = "CA16", type = "total", query_type = "semantic") #> # A tibble: 1 × 4 #> vector type label details #> <chr> <fct> <chr> <chr> #> 1 v_CA16_4809 Total Australian 25% Data; Minority / Origin; Total - Ethnic orig… -find_census_vectors("Australian ethnic", dataset = "CA16", type = "total", query_type = "keyword", interactive = FALSE) +find_census_vectors("Australian ethnic", dataset = "CA16", type = "total", query_type = "keyword", interactive = FALSE) #> # A tibble: 1 × 4 #> vector type label details #> <chr> <fct> <chr> <chr> @@ -506,26 +502,25 @@
Managing variable hierarchy
-list_census_vectors("CA16") %>% +
+#> vector type label units parent_vector aggregation details +#> <chr> <fct> <chr> <fct> <chr> <chr> <chr> +#> 1 v_CA16_4089 Total Western European or… Numb… v_CA16_4044 Additive CA 201… +#> 2 v_CA16_4044 Total European origins Numb… v_CA16_3999 Additive CA 201… +#> 3 v_CA16_3999 Total Total - Ethnic orig… Numb… NA Additive CA 201…+list_census_vectors("CA16") %>% filter(vector == "v_CA16_4092") %>% - parent_census_vectors() + parent_census_vectors() #> # A tibble: 3 × 7 -#> vector type label units paren…¹ aggre…² details -#> <chr> <fct> <chr> <fct> <chr> <chr> <chr> -#> 1 v_CA16_4089 Total Western European origins (exc… Numb… v_CA16… Additi… CA 201… -#> 2 v_CA16_4044 Total European origins Numb… v_CA16… Additi… CA 201… -#> 3 v_CA16_3999 Total Total - Ethnic origin for the… Numb… NA Additi… CA 201… -#> # … with abbreviated variable names ¹parent_vector, ²aggregation
Sometimes we want to traverse the hierarchy in the opposite direction. This is frequently required when looking to compare different variable stems that share the same aggregate variable. As an example, if we want to look the total count of Northern European ethnic origin respondents disaggregated by individual countries, it is pretty easy to do so.
-diff --git a/docs/articles/data_discovery.html b/docs/articles/data_discovery.html index d9f44432..13a41903 100644 --- a/docs/articles/data_discovery.html +++ b/docs/articles/data_discovery.html @@ -51,7 +51,7 @@+# Find the variable indicating the Northern European aggregate -find_census_vectors("Northern European", dataset = "CA16", type = "Total") +find_census_vectors("Northern European", dataset = "CA16", type = "Total") #> # A tibble: 7 × 4 #> vector type label details #> <chr> <fct> <chr> <chr> @@ -540,20 +535,19 @@
Managing variable hierarchy
++#> vector type label units parent_vector aggregation details +#> <chr> <fct> <chr> <fct> <chr> <chr> <chr> +#> 1 v_CA16_4125 Total Danish Numb… v_CA16_4122 Additive CA 201… +#> 2 v_CA16_4128 Total Finnish Numb… v_CA16_4122 Additive CA 201… +#> 3 v_CA16_4131 Total Icelandic Numb… v_CA16_4122 Additive CA 201… +#> 4 v_CA16_4134 Total Norwegian Numb… v_CA16_4122 Additive CA 201… +#> 5 v_CA16_4137 Total Swedish Numb… v_CA16_4122 Additive CA 201… +#> 6 v_CA16_4140 Total Northern European o… Numb… v_CA16_4122 Additive CA 201…# Show all child variable leaves -list_census_vectors("CA16") %>% - filter(vector == "v_CA16_4122") %>% child_census_vectors(leaves = TRUE) +list_census_vectors("CA16") %>% + filter(vector == "v_CA16_4122") %>% child_census_vectors(leaves = TRUE) #> # A tibble: 6 × 7 -#> vector type label units paren…¹ aggre…² details -#> <chr> <fct> <chr> <fct> <chr> <chr> <chr> -#> 1 v_CA16_4125 Total Danish Numb… v_CA16… Additi… CA 201… -#> 2 v_CA16_4128 Total Finnish Numb… v_CA16… Additi… CA 201… -#> 3 v_CA16_4131 Total Icelandic Numb… v_CA16… Additi… CA 201… -#> 4 v_CA16_4134 Total Norwegian Numb… v_CA16… Additi… CA 201… -#> 5 v_CA16_4137 Total Swedish Numb… v_CA16… Additi… CA 201… -#> 6 v_CA16_4140 Total Northern European origins, n.… Numb… v_CA16… Additi… CA 201… -#> # … with abbreviated variable names ¹parent_vector, ²aggregation
The
leaves = TRUE
parameter specifies whether intermediate aggregates are included or not. IfTRUE
then only the lowest level variables are returns - the “leaves” of the @@ -579,7 +573,7 @@Managing variable hierarchy -
Site built with pkgdown 2.0.6.
+Site built with pkgdown 2.0.7.
Census datasets +
list_census_datasets()
-## # A tibble: 29 × 6 -## dataset description geo_d…¹ attri…² refer…³ refer…⁴ -## <chr> <chr> <chr> <chr> <chr> <chr> -## 1 CA1996 1996 Canada Census CA1996 StatCa… 92-351… https:… -## 2 CA01 2001 Canada Census CA01 StatCa… 92-378… https:… -## 3 CA06 2006 Canada Census CA06 StatCa… 92-566… https:… -## 4 CA11 2011 Canada Census and NHS CA11 StatCa… 98-301… https:… -## 5 CA16 2016 Canada Census CA16 StatCa… 98-301… https:… -## 6 CA21 2021 Canada Census CA21 StatCa… 98-301… https:… -## 7 CA01xSD 2001 Canada Census xtab - Structural… CA01 StatCa… 92-378… https:… -## 8 CA06xSD 2006 Canada Census xtab - Structural… CA06 StatCa… 92-566… https:… -## 9 CA11xSD 2011 Canada Census xtab - Structural… CA11 StatCa… 98-301… https:… -## 10 CA16xSD 2016 Canada Census xtab - Structural… CA16 StatCa… 98-301… https:… -## # … with 19 more rows, and abbreviated variable names ¹geo_dataset, -## # ²attribution, ³reference, ⁴reference_url
The
list_census_datasets()
function also provides +## dataset description geo_dataset attribution reference reference_url +## <chr> <chr> <chr> <chr> <chr> <chr> +## 1 CA1996 1996 Canada Census CA1996 StatCan 19… 92-351-U https://www1… +## 2 CA01 2001 Canada Census CA01 StatCan 20… 92-378-X https://www1… +## 3 CA06 2006 Canada Census CA06 StatCan 20… 92-566-X https://www1… +## 4 CA11 2011 Canada Census a… CA11 StatCan 20… 98-301-X… https://www1… +## 5 CA16 2016 Canada Census CA16 StatCan 20… 98-301-X https://www1… +## 6 CA21 2021 Canada Census CA21 StatCan 20… 98-301-X https://www1… +## 7 CA01xSD 2001 Canada Census x… CA01 StatCan 20… 92-378-X https://www1… +## 8 CA06xSD 2006 Canada Census x… CA06 StatCan 20… 92-566-X https://www1… +## 9 CA11xSD 2011 Canada Census x… CA11 StatCan 20… 98-301-X https://www1… +## 10 CA16xSD 2016 Canada Census x… CA16 StatCan 20… 98-301-X https://www1… +## # ℹ 19 more rows
The list_census_datasets()
function also provides
additional background like series reference code, catalogue reference,
and attribution details.
-list_census_vectors('CA21')
list_census_vectors('CA21')
## # A tibble: 7,709 × 7
-## vector type label units paren…¹ aggre…² details
-## <chr> <fct> <chr> <fct> <chr> <chr> <chr>
-## 1 v_CA21_1 Total Population, 2021 Numb… NA Additi… CA 202…
-## 2 v_CA21_2 Total Population, 2016 Numb… NA Additi… CA 202…
-## 3 v_CA21_3 Total Population percentage change,… Numb… NA Averag… CA 202…
-## 4 v_CA21_4 Total Total private dwellings Numb… NA Additi… CA 202…
-## 5 v_CA21_5 Total Private dwellings occupied by… Numb… v_CA21… Additi… CA 202…
-## 6 v_CA21_6 Total Population density per square… Ratio NA Averag… CA 202…
-## 7 v_CA21_7 Total Land area in square kilometres Numb… NA Additi… CA 202…
-## 8 v_CA21_8 Total Total - Age Numb… NA Additi… CA 202…
-## 9 v_CA21_9 Male Total - Age Numb… NA Additi… CA 202…
-## 10 v_CA21_10 Female Total - Age Numb… NA Additi… CA 202…
-## # … with 7,699 more rows, and abbreviated variable names ¹parent_vector,
-## # ²aggregation
+## vector type label units parent_vector aggregation details
+## <chr> <fct> <chr> <fct> <chr> <chr> <chr>
+## 1 v_CA21_1 Total Population, 2021 Numb… NA Additive CA 202…
+## 2 v_CA21_2 Total Population, 2016 Numb… NA Additive CA 202…
+## 3 v_CA21_3 Total Population percenta… Numb… NA Average of… CA 202…
+## 4 v_CA21_4 Total Total private dwell… Numb… NA Additive CA 202…
+## 5 v_CA21_5 Total Private dwellings o… Numb… v_CA21_4 Additive CA 202…
+## 6 v_CA21_6 Total Population density … Ratio NA Average of… CA 202…
+## 7 v_CA21_7 Total Land area in square… Numb… NA Additive CA 202…
+## 8 v_CA21_8 Total Total - Age Numb… NA Additive CA 202…
+## 9 v_CA21_9 Male Total - Age Numb… NA Additive CA 202…
+## 10 v_CA21_10 Female Total - Age Numb… NA Additive CA 202…
+## # ℹ 7,699 more rows
list_census_vectors(dataset)
retrieves an index of all
available vectors for a given dataset from the CensusMapper API or local
cache if recently called. Each Census variable has a vector code
@@ -223,7 +221,7 @@
query_type
argument when calling
-find_census_vectors()
function.
+find_census_vectors()
function.
Note that variable search is optimized for the Census variables in the main Census datasets. While searches generally work for variables in additional datasets such as cross-tabs and taxfiler data, they have not @@ -235,7 +233,7 @@
-find_census_vectors("Oji-cree", dataset = "CA16", type = "total", query_type = "exact")
+find_census_vectors("Oji-cree", dataset = "CA16", type = "total", query_type = "exact")
## # A tibble: 4 × 4
## vector type label details
## <chr> <fct> <chr> <chr>
@@ -245,12 +243,12 @@ Exact search## 4 v_CA16_5930 Total Oji-Cree 25% Data; Work; Total - Language used most often a…
This, on the other hand, will return a warning.
-find_census_vectors("Ojib-cree", dataset = "CA16", type = "total", query_type = "exact")
find_census_vectors("Ojib-cree", dataset = "CA16", type = "total", query_type = "exact")
## Warning: No exact matches found. Please check spelling and try again or consider using semantic or keyword search.
## See ?find_census_vectors() for more details.
##
## Alternatively, you can launch the Censusmapper web API in a browser by calling explore_census_vectors(dataset)
-Unless otherwise specified, find_census_vectors()
will
+
Unless otherwise specified, find_census_vectors()
will
use exact search as the default option.
-find_census_vectors('commute mode', dataset = 'CA16', type = 'female', query_type = 'keyword', interactive = FALSE)
find_census_vectors('commute mode', dataset = 'CA16', type = 'female', query_type = 'keyword', interactive = FALSE)
## # A tibble: 7 × 4 ## vector type label details ## <chr> <fct> <chr> <chr> @@ -278,7 +276,7 @@
, which will prompt the user with a console menu option to see the rest of the matches or not. If using -Keyword searchinteractive = TRUE
find_census_vectors()
in a script or reproducible +find_census_vectors()
in a script or reproducible documentation, we recommend setting this argument tointeractive = FALSE
. @@ -291,7 +289,7 @@Semantic search
+-find_census_vectors("after tax incomes", dataset = "CA16", type = "total", query_type = "semantic")
find_census_vectors("after tax incomes", dataset = "CA16", type = "total", query_type = "semantic")
## # A tibble: 56 × 4
## vector type label details
## <chr> <fct> <chr> <chr>
@@ -305,19 +303,19 @@ Semantic search## 8 v_CA16_2312 Total $10,000 to $19,999 Income…
## 9 v_CA16_2315 Total $20,000 to $29,999 Income…
## 10 v_CA16_2318 Total $30,000 to $39,999 Income…
-## # … with 46 more rows
+## # ℹ 46 more rows
Semantic search is more robust to spelling and punctuation issues that may come up with exact search. For example, while this throws a warning:
-find_census_vectors("ojib cree", dataset = "CA16", type = "total", query_type = "exact")
find_census_vectors("ojib cree", dataset = "CA16", type = "total", query_type = "exact")
## Warning: No exact matches found. Please check spelling and try again or consider using semantic or keyword search.
## See ?find_census_vectors() for more details.
##
## Alternatively, you can launch the Censusmapper web API in a browser by calling explore_census_vectors(dataset)
This will find the correct Census vector.
-find_census_vectors('ojib cree', dataset = 'CA16', type = 'total', query_type = 'semantic')
find_census_vectors('ojib cree', dataset = 'CA16', type = 'total', query_type = 'semantic')
## Multiple possible matches. Results ordered by closeness.
## # A tibble: 4 × 4
## vector type label details
@@ -446,21 +444,21 @@ Viewing available Census regions
-list_census_regions('CA21')
+list_census_regions('CA21')
## # A tibble: 5,518 × 8
-## region name level pop munic…¹ CMA_UID CD_UID PR_UID
-## <chr> <chr> <chr> <int> <chr> <chr> <chr> <chr>
-## 1 01 Canada C 36991981 NA NA NA NA
-## 2 35 Ontario PR 14223942 Ont. NA NA NA
-## 3 24 Quebec PR 8501833 Que. NA NA NA
-## 4 59 British Columbia PR 5000879 B.C. NA NA NA
-## 5 48 Alberta PR 4262635 Alta. NA NA NA
-## 6 46 Manitoba PR 1342153 Man. NA NA NA
-## 7 47 Saskatchewan PR 1132505 Sask. NA NA NA
-## 8 12 Nova Scotia PR 969383 N.S. NA NA NA
-## 9 13 New Brunswick PR 775610 N.B. NA NA NA
-## 10 10 Newfoundland and Labrador PR 510550 N.L. NA NA NA
-## # … with 5,508 more rows, and abbreviated variable name ¹municipal_status
+## region name level pop municipal_status CMA_UID CD_UID PR_UID
+## <chr> <chr> <chr> <int> <chr> <chr> <chr> <chr>
+## 1 01 Canada C 3.70e7 NA NA NA NA
+## 2 35 Ontario PR 1.42e7 Ont. NA NA NA
+## 3 24 Quebec PR 8.50e6 Que. NA NA NA
+## 4 59 British Columbia PR 5.00e6 B.C. NA NA NA
+## 5 48 Alberta PR 4.26e6 Alta. NA NA NA
+## 6 46 Manitoba PR 1.34e6 Man. NA NA NA
+## 7 47 Saskatchewan PR 1.13e6 Sask. NA NA NA
+## 8 12 Nova Scotia PR 9.69e5 N.S. NA NA NA
+## 9 13 New Brunswick PR 7.76e5 N.B. NA NA NA
+## 10 10 Newfoundland and … PR 5.11e5 N.L. NA NA NA
+## # ℹ 5,508 more rows
There are 53 CSD and 12 CD municipal status codes based on official
designations used by provinces, territories, and federal authorities.
These are often used to distinguish Census divisions and subdivisions
@@ -479,7 +477,7 @@
-search_census_regions("Vancouver","CA21")
search_census_regions("Vancouver","CA21")
## # A tibble: 7 × 8
## region name level pop municipal_status CMA_UID CD_UID PR_UID
## <chr> <chr> <chr> <int> <chr> <chr> <chr> <chr>
@@ -531,7 +529,7 @@ Exploring C
diff --git a/docs/articles/index.html b/docs/articles/index.html
index 7a2d8daf..1ead90c1 100644
--- a/docs/articles/index.html
+++ b/docs/articles/index.html
@@ -23,7 +23,7 @@
@@ -136,7 +136,7 @@ Additional datasets
diff --git a/docs/articles/intersecting_geometries.html b/docs/articles/intersecting_geometries.html
index c3d779fa..dff03aeb 100644
--- a/docs/articles/intersecting_geometries.html
+++ b/docs/articles/intersecting_geometries.html
@@ -51,7 +51,7 @@
@@ -136,7 +136,7 @@ Bring custom data and
geographies or other geospatial data of interest and want to be able to
quickly and easily identify the collection of census features that
correspond to that region.
-
The get_intersecting_geometries()
function is projection
+
The get_intersecting_geometries()
function is projection
agnostic and accepts any valid sf
or sfc
class
object as input. These objects are then reprojected into lat/lon
coordinates on the backend to facilitate the intersecting join on the
@@ -165,9 +165,9 @@
A simple example
-station_city_ids <- get_intersecting_geometries("CA16", level = "CSD", geometry = cov_station_buffers,
+station_city_ids <- get_intersecting_geometries("CA16", level = "CSD", geometry = cov_station_buffers,
quiet=TRUE)
-station_ct_ids <- get_intersecting_geometries("CA16", level = "CT", geometry = cov_station_buffers,
+station_ct_ids <- get_intersecting_geometries("CA16", level = "CT", geometry = cov_station_buffers,
quiet=TRUE)
These return a list of census geographic identifiers suitable for use
in the ‘region’ argument in get_census
. We may be
@@ -175,10 +175,10 @@
A simple example
variables <- c(mode_base="v_CA16_5792",transit="v_CA16_5801",walk="v_CA16_5804")
-station_city <- get_census("CA16", regions = station_city_ids, vectors = variables,
+station_city <- get_census("CA16", regions = station_city_ids, vectors = variables,
geo_format = 'sf', quiet=TRUE) %>%
filter(name == "Vancouver (CY)")
-station_cts <- get_census("CA16", regions = station_ct_ids, vectors = variables,
+station_cts <- get_census("CA16", regions = station_ct_ids, vectors = variables,
geo_format = 'sf', quiet=TRUE)
To understand how these relate we plot the data.
@@ -195,9 +195,9 @@ A simple exampleTo get a closer match we can cut out the dissemination areas
intersecting the station catchment areas.
-station_das <- get_intersecting_geometries("CA16", level = "DA", geometry = cov_station_buffers,
+station_das <- get_intersecting_geometries("CA16", level = "DA", geometry = cov_station_buffers,
quiet=TRUE) %>%
- get_census("CA16", regions = ., vectors=variables, geo_format = 'sf', quiet=TRUE)
+ get_census("CA16", regions = ., vectors=variables, geo_format = 'sf', quiet=TRUE)
ggplot(station_city) +
geom_sf(fill=NA) +
@@ -215,7 +215,7 @@ A simple exampleget_intersecting_geometries
call and then filter down to
those intersecting the station buffers.
-station_das2 <- get_census("CA16", regions = station_ct_ids, vectors=variables,
+station_das2 <- get_census("CA16", regions = station_ct_ids, vectors=variables,
geo_format = 'sf', level="DA", quiet=TRUE) %>%
sf::st_filter(cov_station_buffers)
@@ -268,7 +268,7 @@ Addendum
-Site built with pkgdown 2.0.6.
+Site built with pkgdown 2.0.7.
diff --git a/docs/articles/statcan_attribute_files.html b/docs/articles/statcan_attribute_files.html
index 83a31f3d..9e0e90e0 100644
--- a/docs/articles/statcan_attribute_files.html
+++ b/docs/articles/statcan_attribute_files.html
@@ -51,7 +51,7 @@
@@ -151,7 +151,7 @@ Match between Censu
basic building block of census geographies, and tags other levels of
geography the Census Block lies in.
-attributes <- get_statcan_geographic_attributes("2021")
+attributes <- get_statcan_geographic_attributes("2021")
attributes %>% colnames()
#> [1] "PRUID_PRIDU" "PRDGUID_PRIDUGD"
@@ -230,7 +230,7 @@ Match between Censu
diff --git a/docs/articles/statcan_wds.html b/docs/articles/statcan_wds.html
index 12d642d5..9c29b172 100644
--- a/docs/articles/statcan_wds.html
+++ b/docs/articles/statcan_wds.html
@@ -51,7 +51,7 @@
@@ -133,7 +133,7 @@ StatCan WDS
library(tidyr)
library(ggplot2)
Some census datasets have not been imported into CensusMapper, and
-thus aren’t available via the get_census()
function. But
+thus aren’t available via the get_census()
function. But
the data can be queried directly from the Statistics
Canada Web Data Service for the 2021 census, as well as geographic
boundary files.
@@ -156,7 +156,7 @@ Ukrainians by Federal Elector
base characteristic for ethnic origin and the entry referencing
“Ukrainian” that’s a descendant of the base characteristic.
-metadata <- get_statcan_wds_metadata("2021","FED")
+metadata <- get_statcan_wds_metadata("2021","FED")
characteristics <- metadata |>
filter(`Codelist en`=="Characteristic") |>
@@ -167,7 +167,7 @@ Ukrainians by Federal Elector
ukranian <- characteristics |>
filter(grepl("Ukrainian",en), `Parent ID`==ethnic_base$ID)
-selected_characteristics <- bind_rows(ethnic_base,ukranian)
+selected_characteristics <- bind_rows(ethnic_base,ukranian)
selected_characteristics |> select(ID,en)
#> # A tibble: 2 × 2
@@ -182,7 +182,7 @@ Ukrainians by Federal Elector
filter(`Codelist ID`=="CL_GEO_FED") |>
pull(ID)
-data <- get_statcan_wds_data(dguids,members=selected_characteristics$ID,gender="Total")
+data <- get_statcan_wds_data(dguids,members=selected_characteristics$ID,gender="Total")
The data comes enriched with metadata to make working with it easier,
in particular the CHARACTERISTIC_NAME
column contains plain
language names. Now we can transform the data to compute
@@ -206,7 +206,7 @@
To map the data we have to get the geographies.
-fed_geos <- get_statcan_geographies("2021","FED")
fed_geos <- get_statcan_geographies("2021","FED")
With these we can join on our census data and map it.
fed_geos |>
@@ -239,7 +239,7 @@ Ukrainians by Federal Elector
diff --git a/docs/authors.html b/docs/authors.html
index 02fd1809..e3bc0f3c 100644
--- a/docs/authors.html
+++ b/docs/authors.html
@@ -23,7 +23,7 @@
Access, retrieve, and work with Canadian Census data and geography.
cancensus requires a valid CensusMapper API key to use. You can obtain a free API key by signing up for a CensusMapper account. To check your API key, just go to “Edit Profile” (in the top-right of the CensusMapper menu bar). Once you have your key, you can store it in your system environment so it is automatically used in API calls. To do so just enter set_cancensus_api_key(<your_api_key>', install = TRUE)
.
cancensus requires a valid CensusMapper API key to use. You can obtain a free API key by signing up for a CensusMapper account. To check your API key, just go to “Edit Profile” (in the top-right of the CensusMapper menu bar). Once you have your key, you can store it in your system environment so it is automatically used in API calls. To do so just enter set_cancensus_api_key('<your_api_key>', install = TRUE)
.
CensusMapper API keys are free and public API quotas are generous; however, due to incremental costs of serving large quantities of data, there are some limits to API usage in place. For most use cases, these API limits should not be an issue. Production uses with large extracts of detailed geographies may run into API quota limits.
The new get_intersecting_geometries
function has a separate API quota. This functionality puts higher demands on server resources than other API calls and therefore comes from a different bucket. By default user keys are capped to 500 region identifiers a day or 5000 per month. This should suffice for most casual use cases, but we will continue to monitor the impact on server load and may increase the default limits in the future.
For larger quotas, please get in touch with Jens directly.
@@ -162,13 +162,13 @@For performance reasons, and to avoid unnecessarily drawing down API quotas, cancensus caches data queries under the hood. By default, cancensus caches in R’s temporary directory, but this cache is not persistent across sessions. In order to speed up performance, reduce quota usage, and reduce the need for unnecessary network calls, we recommend assigning a persistent local cache using set_cancensus_cache_path(<local cache path>, install = TRUE)
, this enables more efficient loading and reuse of downloaded data. Users will be prompted with a suggestion to change their default cache location when making API calls if one has not been set yet.
Starting with version 0.5.2 cancensus will automatically check if for data that has been recalled by Statistics Canada and is stored in the local cache via the new data recall API implemented in CensusMapper. Statistics Canada occasionally detects and corrects errors in their census data releases, and cancensus will download a list of recalled data at the first invocation of get_census()
in each session and emit a warning if it detected locally cached data that has been recalled. Removal of the cached recalled data has to be done explicitly by the user via the remove_recalled_chached_data()
function. If data was cached with cancensus versions prior to version 0.5.0 there is insufficient metadata to determine all instances of recalled cached data, but the package will check every time cached data is loaded and can identify recalled data at this point at the latest and issues a warning if recalled data is loaded.
For performance reasons, and to avoid unnecessarily drawing down API quotas, cancensus caches data queries under the hood. By default, cancensus caches in R’s temporary directory, but this cache is not persistent across sessions. In order to speed up performance, reduce quota usage, and reduce the need for unnecessary network calls, we recommend assigning a persistent local cache using set_cancensus_cache_path('<local cache path>', install = TRUE)
, this enables more efficient loading and reuse of downloaded data. Users will be prompted with a suggestion to change their default cache location when making API calls if one has not been set yet.
Starting with version 0.5.2 cancensus will automatically check if for data that has been recalled by Statistics Canada and is stored in the local cache via the new data recall API implemented in CensusMapper. Statistics Canada occasionally detects and corrects errors in their census data releases, and cancensus will download a list of recalled data at the first invocation of get_census()
in each session and emit a warning if it detected locally cached data that has been recalled. Removal of the cached recalled data has to be done explicitly by the user via the remove_recalled_chached_data()
function. If data was cached with cancensus versions prior to version 0.5.0 there is insufficient metadata to determine all instances of recalled cached data, but the package will check every time cached data is loaded and can identify recalled data at this point at the latest and issues a warning if recalled data is loaded.
cancensus can access Statistics Canada Census data for Census years 1996, 2001, 2006, 2011, 2016, and 2021. You can run list_census_datasets
to check what datasets are currently available for access through the CensusMapper API. Additional data for the 2021 Census will be included in Censusmapper within a day or two after public release by Statistics Canada. Statistics Canada maintains a release schedule for the Census 2021 Program which can be viewed on their website.
cancensus can access Statistics Canada Census data for Census years 1996, 2001, 2006, 2011, 2016, and 2021. You can run list_census_datasets
to check what datasets are currently available for access through the CensusMapper API. Additional data for the 2021 Census will be included in CensusMapper within a day or two after public release by Statistics Canada. Statistics Canada maintains a release schedule for the Census 2021 Program which can be viewed on their website.
Thanks to contributions by the Canada Mortgage and Housing Corporation (CMHC), cancensus now includes additional Census-linked datasets as open-data releases. These include annual taxfiler data at the census tract level for tax years 2000 through 2018, which includes data on incomes and demographics, as well as specialized crosstabs for Structural type of dwelling by Document type, which details occupancy status for residences. These crosstabs are available for the 2001, 2006, 2011, 2016, and 2021 Census years at all levels starting with census tract.
There is also an interactive tool that is available at the CensusMapper API to visually select regions and variables and generate code for the API call. Calling explore_census_vectors(dataset = "CA16")
or explore_census_regions(dataset = "CA16")
will open a new browser window to this interactive tool, preconfigured for whichever Census dataset is set as an argument.
cancensus can return census data with or without associated Census geographical information that can be used for mapping and GIS. By default, cancensus returns tidy tabular data only, but has options to return spatial data objects in either sf or sp formats.
# Return data only
-census_data <- get_census(dataset='CA16', regions=list(CMA="59933"),
+census_data <- get_census(dataset='CA16', regions=list(CMA="59933"),
vectors=c("v_CA16_408","v_CA16_409","v_CA16_410"), level='CSD')
# Return an sf-class data frame
-census_data <- get_census(dataset='CA16', regions=list(CMA="59933"),
+census_data <- get_census(dataset='CA16', regions=list(CMA="59933"),
vectors=c("v_CA16_408","v_CA16_409","v_CA16_410"), level='CSD', geo_format = "sf")
cancensus attempts to minimize bandwidth usage and download time by caching downloads. When attempting to download data that has previously been downloaded, cancensus will instead access the locally cached equivalent.
If you wish to cite cancensus:
-von Bergmann, J., Aaron Jacobs, Dmitry Shkolnik (2022). cancensus: R package to access, retrieve, and work with Canadian Census data and geography. v0.5.5.
+von Bergmann, J., Aaron Jacobs, Dmitry Shkolnik (2022). cancensus: R package to access, retrieve, and work with Canadian Census data and geography. v0.5.6.
A BibTeX entry for LaTeX users is
@Manual{cancensus,
author = {Jens {von Bergmann} and Dmitry Shkolnik and Aaron Jacobs},
title = {cancensus: R package to access, retrieve, and work with Canadian Census data and geography},
year = {2022},
- note = {R package version 0.5.5},
+ note = {R package version 0.5.6},
url = {https://mountainmath.github.io/cancensus/}
}
list_census_regions()
+list_census_regions()
sf
package when user requests spatial data but does not have the required package installed as opposed to erroring out.keep_parent
when calling child_census_vectors()
that retains the input parent variable in the list of result. We found that in many cases user would follow up a call to child_census_vectors()
with a bind_rows(...)
to do this, so this should save a step.keep_parent
when calling child_census_vectors()
that retains the input parent variable in the list of result. We found that in many cases user would follow up a call to child_census_vectors()
with a bind_rows(...)
to do this, so this should save a step.find_census_vectors()
+find_census_vectors()
find_census_vectors()
and deprecation of `search_census_vectors(). See the Data discovery: resources for finding available and relevant data vignette for additional information.list_census_regions()
+find_census_vectors()
and deprecation of `search_census_vectors(). See the Data discovery: resources for finding available and relevant data vignette for additional information.list_census_regions()
list_census_datasets()
+list_census_datasets()
explore_census_regions
and explore_census_vectors
which open a browser page towards the interactive discovery and selection tools on the Censusmapper website
attribution_for_dataset
which provides accurate attribution information for citation and visualizations for a given dataset.get_census_geometry()
is now hard-deprecated and will stop the program flow. Use get_census()
instead.get_census_geometry()
is now hard-deprecated and will stop the program flow. Use get_census()
instead.list_census_vectors()
changed to have quiet = TRUE
+list_census_vectors()
changed to have quiet = TRUE
geographic level to return the data for, valid choices are -"PR","CD","CMACA","CSD","CT","ADA","DA","ER","FED","DPL","POPCNTR"
geographic level to return the data for, valid choices are -"PR","CD","CMACA","CSD","CT","ADA","DA","ER","FED","DPL","POPCNTR"
as_census_region_list()
Convert a (suitably filtered) data frame from
-list_census_regions
to a list suitable for passing to
-get_census
.
list_census_regions
to a list suitable for passing to
+get_census
.
# list add the cached census data
list_cancensus_cache()
-#> # A tibble: 1,453 × 11
-#> path dataset regions level vectors created_at version size
-#> <chr> <chr> <chr> <chr> <chr> <dttm> <chr> <dbl>
-#> 1 CM_data_009… CA06 "[\"{\… DA "[]" 2022-05-21 15:28:16 d.1 1663
-#> 2 CM_data_00a… CA16 "[\"{\… DA "[\"Po… 2022-05-14 16:24:07 d.1 16663
-#> 3 CM_data_014… CA06 "{\"CS… CT "[\"v_… 2022-11-03 04:34:33 d.3 13801
-#> 4 CM_data_016… CA01 "{\"CS… DB "[\"Po… 2022-12-12 12:54:14 d.3 179740
-#> 5 CM_data_016… CA16 "[\"{\… DA "[]" 2022-05-21 15:28:24 d.1 1658
-#> 6 CM_data_01c… CA16 "[\"{\… CT "[\"v_… 2022-07-13 15:23:08 d.1 5258
-#> 7 CM_data_01f… CA1996 "{\"CS… CSD "[\"v_… 2022-08-18 19:13:18 d.2 8898
-#> 8 CM_data_024… CA16 "[\"{\… Regi… "[\"v_… 2022-04-27 23:26:47 d.1 3603
-#> 9 CM_data_02b… CA21 "{\"CD… CT "[\"v_… 2022-12-31 09:37:21 d.4 361
-#> 10 CM_data_02b… CA16 "{\"C\… CT "[\"v_… 2022-10-06 10:39:55 d.2 143505
-#> # … with 1,443 more rows, and 3 more variables: last_accessed <dttm>,
-#> # access_count <dbl>, resolution <chr>
+#> # A tibble: 3,278 × 11
+#> path dataset regions level vectors created_at version size
+#> <chr> <chr> <chr> <chr> <chr> <dttm> <chr> <dbl>
+#> 1 CM_data_0008… CA16 "{\"CS… Regi… "[\"v_… 2023-06-14 15:39:12 d.4 874
+#> 2 CM_data_0017… CA16 "{\"CS… Regi… "[\"v_… 2023-05-24 18:34:54 d.4 516
+#> 3 CM_data_0023… CA11 "{\"CS… Regi… "[\"v_… 2023-05-16 21:46:25 d.4 485
+#> 4 CM_data_0039… CA21 "{\"CS… Regi… "[\"v_… 2023-05-24 19:32:51 d.4 533
+#> 5 CM_data_0054… CA21 "{\"CS… DA "[\"v_… 2023-08-28 15:19:19 d.4 620
+#> 6 CM_data_0056… CA16 "{\"CS… Regi… "[\"v_… 2023-05-24 18:32:15 d.4 525
+#> 7 CM_data_006c… CA21 "{\"CS… Regi… "[\"v_… 2023-05-24 18:29:31 d.4 529
+#> 8 CM_data_007f… CA21 "{\"CM… Regi… "[]" 2023-01-26 07:18:01 d.4 1882
+#> 9 CM_data_0084… CA16 "{\"CS… Regi… "[\"v_… 2023-06-14 15:32:37 d.4 707
+#> 10 CM_data_008d… CA11 "{\"CS… Regi… "[\"v_… 2023-05-24 18:36:59 d.4 478
+#> # ℹ 3,268 more rows
+#> # ℹ 3 more variables: last_accessed <dttm>, access_count <dbl>,
+#> # resolution <chr>
list_census_regions('CA16')
-#> Reading regions list from local cache.
-#> # A tibble: 5,518 × 8
-#> region name level pop munic…¹ CMA_UID CD_UID PR_UID
-#> <chr> <chr> <chr> <int> <chr> <chr> <chr> <chr>
-#> 1 01 Canada C 35151728 NA NA NA NA
-#> 2 35 Ontario PR 13448494 NA NA NA NA
-#> 3 24 Quebec PR 8164361 NA NA NA NA
-#> 4 59 British Columbia PR 4648055 NA NA NA NA
-#> 5 48 Alberta PR 4067175 NA NA NA NA
-#> 6 46 Manitoba PR 1278365 NA NA NA NA
-#> 7 47 Saskatchewan PR 1098352 NA NA NA NA
-#> 8 12 Nova Scotia PR 923598 NA NA NA NA
-#> 9 13 New Brunswick PR 747101 NA NA NA NA
-#> 10 10 Newfoundland and Labrador PR 519716 NA NA NA NA
-#> # … with 5,508 more rows, and abbreviated variable name ¹municipal_status
+ if (FALSE) {
+list_census_regions('CA16')
+}
# Query parent vectors directly using vector identifier
parent_census_vectors("v_CA16_2519")
#> # A tibble: 1 × 7
-#> vector type label units paren…¹ aggre…² details
-#> <chr> <fct> <chr> <fct> <chr> <chr> <chr>
-#> 1 v_CA16_2510 Total Total - Low-income status in … Numb… NA Additi… CA 201…
-#> # … with abbreviated variable names ¹parent_vector, ²aggregation
+#> vector type label units parent_vector aggregation details
+#> <chr> <fct> <chr> <fct> <chr> <chr> <chr>
+#> 1 v_CA16_2510 Total Total - Low-income … Numb… NA Additive CA 201…
if (FALSE) {
# Example using multiple vectors coerced into a list
parent_census_vectors(c("v_CA16_2519","v_CA16_2520","v_CA16_2521"))
@@ -149,7 +148,7 @@ Examples
search_census_vectors('Ojibway', 'CA16')
#> Warning: search_census_vectors(). See ?find_census_vectors() for more robust search functions.
#> # A tibble: 24 × 7
-#> vector type label units paren…¹ aggre…² details
-#> <chr> <fct> <chr> <fct> <chr> <chr> <chr>
-#> 1 v_CA16_617 Total Ojibway-Potawatomi languages Numb… v_CA16… Additi… CA 201…
-#> 2 v_CA16_618 Male Ojibway-Potawatomi languages Numb… v_CA16… Additi… CA 201…
-#> 3 v_CA16_619 Female Ojibway-Potawatomi languages Numb… v_CA16… Additi… CA 201…
-#> 4 v_CA16_623 Total Ojibway Numb… v_CA16… Additi… CA 201…
-#> 5 v_CA16_624 Male Ojibway Numb… v_CA16… Additi… CA 201…
-#> 6 v_CA16_625 Female Ojibway Numb… v_CA16… Additi… CA 201…
-#> 7 v_CA16_1424 Total Ojibway-Potawatomi languages Numb… v_CA16… Additi… CA 201…
-#> 8 v_CA16_1425 Male Ojibway-Potawatomi languages Numb… v_CA16… Additi… CA 201…
-#> 9 v_CA16_1426 Female Ojibway-Potawatomi languages Numb… v_CA16… Additi… CA 201…
-#> 10 v_CA16_1430 Total Ojibway Numb… v_CA16… Additi… CA 201…
-#> # … with 14 more rows, and abbreviated variable names ¹parent_vector,
-#> # ²aggregation
+#> vector type label units parent_vector aggregation details
+#> <chr> <fct> <chr> <fct> <chr> <chr> <chr>
+#> 1 v_CA16_617 Total Ojibway-Potawatom… Numb… v_CA16_569 Additive CA 201…
+#> 2 v_CA16_618 Male Ojibway-Potawatom… Numb… v_CA16_570 Additive CA 201…
+#> 3 v_CA16_619 Female Ojibway-Potawatom… Numb… v_CA16_571 Additive CA 201…
+#> 4 v_CA16_623 Total Ojibway Numb… v_CA16_617 Additive CA 201…
+#> 5 v_CA16_624 Male Ojibway Numb… v_CA16_618 Additive CA 201…
+#> 6 v_CA16_625 Female Ojibway Numb… v_CA16_619 Additive CA 201…
+#> 7 v_CA16_1424 Total Ojibway-Potawatom… Numb… v_CA16_1376 Additive CA 201…
+#> 8 v_CA16_1425 Male Ojibway-Potawatom… Numb… v_CA16_1377 Additive CA 201…
+#> 9 v_CA16_1426 Female Ojibway-Potawatom… Numb… v_CA16_1378 Additive CA 201…
+#> 10 v_CA16_1430 Total Ojibway Numb… v_CA16_1424 Additive CA 201…
+#> # ℹ 14 more rows
if (FALSE) {
# This will return a warning that no match was found, but will suggest similar terms.
search_census_vectors('Ojibwe', 'CA16', 'Total')
@@ -153,7 +152,7 @@ Examples