From 569c5eb59d59aa5f191549753e7cf89c30287644 Mon Sep 17 00:00:00 2001
From: Jens von Bergmann
Date: Mon, 23 Jan 2023 08:30:59 -0800
Subject: [PATCH 1/8] dontrun for list_census_regions example
---
R/census_regions.R | 2 ++
man/list_census_regions.Rd | 2 ++
2 files changed, 4 insertions(+)
diff --git a/R/census_regions.R b/R/census_regions.R
index a764b5fa..705b75c2 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"))
diff --git a/man/list_census_regions.Rd b/man/list_census_regions.Rd
index 2e224e92..facb9a19 100644
--- a/man/list_census_regions.Rd
+++ b/man/list_census_regions.Rd
@@ -43,5 +43,7 @@ Returns a data frame with the following columns:
Query the CensusMapper API for available regions in a given dataset.
}
\examples{
+\dontrun{
list_census_regions('CA16')
}
+}
From f98a5c25d3b966458d67f992cb7eac6eea178cb5 Mon Sep 17 00:00:00 2001
From: Jens von Bergmann
Date: Mon, 23 Jan 2023 08:32:00 -0800
Subject: [PATCH 2/8] bump version for new dev version stub
---
DESCRIPTION | 2 +-
README.md | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/DESCRIPTION b/DESCRIPTION
index dae0b64b..f2d6c992 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"),
diff --git a/README.md b/README.md
index 0187dd36..949b2cf8 100644
--- a/README.md
+++ b/README.md
@@ -139,7 +139,7 @@ There are several other jurisdiction where census data is available via R packag
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.
+ access, retrieve, and work with Canadian Census data and geography. v0.5.6.
A BibTeX entry for LaTeX users is
@@ -148,7 +148,7 @@ A BibTeX entry for LaTeX users is
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/}
}
```
From 4bab4cdf0611801d98b621230426a30d9f2619fb Mon Sep 17 00:00:00 2001
From: Jens von Bergmann
Date: Tue, 11 Apr 2023 12:10:06 -0700
Subject: [PATCH 3/8] fix issue with named vectors in case data for geography
is unavailable
---
NEWS.md | 4 ++++
R/cancensus.R | 5 ++++-
cran-comments.md | 3 +++
3 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/NEWS.md b/NEWS.md
index 4db26f3b..5ad9220b 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,3 +1,7 @@
+# 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
+
# 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 cbae05bb..fe4f5465 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/cran-comments.md b/cran-comments.md
index 003bf85a..66901ba3 100644
--- a/cran-comments.md
+++ b/cran-comments.md
@@ -1,3 +1,6 @@
+# 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
+
# Update 0.5.5
- add functionality for direct access to StatCan census WDS for 2021
- add functionality to download original StatCan geographies for 2021
From 13cc052b74a57dc7f6c9b184e739fe7c8e26505d Mon Sep 17 00:00:00 2001
From: Jens von Bergmann
Date: Tue, 18 Apr 2023 14:34:26 -0700
Subject: [PATCH 4/8] population centres and FSA geographies and adata
---
DESCRIPTION | 2 +-
NEWS.md | 2 +
R/geographies.R | 16 +-
R/wds.R | 4 +-
cran-comments.md | 2 +
docs/404.html | 4 +-
docs/LICENSE-text.html | 4 +-
...ngs_by_document_type_cross_tabulation.html | 14 +-
docs/articles/Making_maps_with_cancensus.html | 16 +-
.../figure-html/unnamed-chunk-4-1.png | Bin 104215 -> 104132 bytes
.../htmlwidgets-1.6.1/htmlwidgets.js | 901 ++++++++++++++++++
docs/articles/Taxfiler_Data.html | 20 +-
docs/articles/cancensus.html | 44 +-
docs/articles/data_discovery.html | 32 +-
docs/articles/index.html | 4 +-
docs/articles/intersecting_geometries.html | 20 +-
docs/articles/statcan_attribute_files.html | 6 +-
docs/articles/statcan_wds.html | 14 +-
docs/authors.html | 4 +-
docs/index.html | 31 +-
docs/news/index.html | 27 +-
docs/pkgdown.yml | 4 +-
docs/reference/CODES_TABLE.html | 4 +-
docs/reference/COV_SKYTRAIN_STATIONS.html | 4 +-
.../add_unique_names_to_region_list.html | 4 +-
docs/reference/as_census_region_list.html | 4 +-
docs/reference/census_vectors.html | 4 +-
docs/reference/child_census_vectors.html | 4 +-
docs/reference/dataset_attribution.html | 4 +-
docs/reference/explore_census_regions.html | 4 +-
docs/reference/explore_census_vectors.html | 4 +-
docs/reference/find_census_vectors.html | 4 +-
docs/reference/get_census.html | 4 +-
docs/reference/get_census_geometry.html | 4 +-
.../get_intersecting_geometries.html | 4 +-
docs/reference/get_recalled_database.html | 4 +-
docs/reference/get_statcan_geo_suite.html | 4 +-
.../get_statcan_geographic_attributes.html | 4 +-
docs/reference/get_statcan_geographies.html | 6 +-
.../get_statcan_geography_relationships.html | 4 +-
docs/reference/get_statcan_wds_data.html | 4 +-
docs/reference/get_statcan_wds_metadata.html | 6 +-
docs/reference/index.html | 8 +-
docs/reference/label_vectors.html | 4 +-
docs/reference/list_cancensus_cache.html | 28 +-
docs/reference/list_census_datasets.html | 4 +-
docs/reference/list_census_regions.html | 23 +-
docs/reference/list_census_vectors.html | 4 +-
docs/reference/list_recalled_cached_data.html | 4 +-
docs/reference/parent_census_vectors.html | 4 +-
.../remove_from_cancensus_cache.html | 4 +-
.../remove_recalled_cached_data.html | 4 +-
docs/reference/search_census_regions.html | 4 +-
docs/reference/search_census_vectors.html | 4 +-
docs/reference/set_cancensus_api_key.html | 4 +-
docs/reference/set_cancensus_cache_path.html | 4 +-
docs/reference/show_cancensus_api_key.html | 4 +-
docs/reference/show_cancensus_cache_path.html | 4 +-
man/get_statcan_geographies.Rd | 2 +-
man/get_statcan_wds_metadata.Rd | 2 +-
60 files changed, 1134 insertions(+), 236 deletions(-)
create mode 100644 docs/articles/Making_maps_with_cancensus_files/htmlwidgets-1.6.1/htmlwidgets.js
diff --git a/DESCRIPTION b/DESCRIPTION
index f2d6c992..d2af7e92 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -24,7 +24,7 @@ Imports: digest (>= 0.1),
httr (>= 1.0.0),
jsonlite (>= 1.0),
rlang
-RoxygenNote: 7.2.1
+RoxygenNote: 7.2.3
Suggests: knitr,
ggplot2,
leaflet,
diff --git a/NEWS.md b/NEWS.md
index 5ad9220b..71cbe0ea 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,6 +1,8 @@
# 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
# cancensus 0.5.5
diff --git a/R/geographies.R b/R/geographies.R
index fe5ce12f..71ec90d7 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,9 +35,9 @@ 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")
+ geo_base_path <- cancensus:::cache_path("geographies")
if (!dir.exists(geo_base_path)) dir.create(geo_base_path)
geo_base_path <- file.path(geo_base_path,type)
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/wds.R b/R/wds.R
index 7e595504..04f75895 100644
--- a/R/wds.R
+++ b/R/wds.R
@@ -6,7 +6,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 refresh default is `FALSE` will refresh the temporary cache if `TRUE`
#' @return tibble with the metadata
#'
@@ -18,7 +18,7 @@
#' @export
get_statcan_wds_metadata <- function(census_year,level,refresh=FALSE){
valid_census_years <- c("2021")
- valid_levels <- c("PR","CD","CMACA","CSD","CT","ADA","DA","ER","FED","DPL","POPCNTR")
+ valid_levels <- c("PR","CD","CMACA","CSD","CT","ADA","DA","ER","FED","DPL","POPCNTR","FSA")
if (!(census_year %in% valid_census_years)) {
stop(paste0("Census year must be one of ",paste0(valid_census_years,collapse = ", "),"."))
}
diff --git a/cran-comments.md b/cran-comments.md
index 66901ba3..3fbce461 100644
--- a/cran-comments.md
+++ b/cran-comments.md
@@ -1,5 +1,7 @@
# 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
# Update 0.5.5
- add functionality for direct access to StatCan census WDS for 2021
diff --git a/docs/404.html b/docs/404.html
index af0f1d6f..d7d1da8e 100644
--- a/docs/404.html
+++ b/docs/404.html
@@ -50,7 +50,7 @@
cancensus
- 0.5.5
+ 0.5.6
@@ -139,7 +139,7 @@ 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 @@
cancensus
- 0.5.5
+ 0.5.6
@@ -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 @@
cancensus
- 0.5.5
+ 0.5.6
@@ -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`)
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.
@@ -237,7 +237,7 @@ 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.