Skip to content

Commit 2833171

Browse files
authored
Merge pull request #205 from mountainMath/v0.5.7
V0.5.7
2 parents 40f4ba9 + 6ef477f commit 2833171

74 files changed

Lines changed: 384 additions & 244 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ data_cache
88
R/local_server_setup.R
99
inst/doc
1010
inst/cache
11-
cancensus.Rproj
1211
doc
1312
Meta
1413
CRAN-RELEASE

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: cancensus
22
Type: Package
33
Title: Access, Retrieve, and Work with Canadian Census Data and Geography
4-
Version: 0.5.6
4+
Version: 0.5.7
55
Authors@R: c(
66
person("Jens", "von Bergmann", email = "jens@mountainmath.ca", role = c("aut"), comment = "API creator and maintainer"),
77
person("Dmitry", "Shkolnik", email = "shkolnikd@gmail.com", role = c("aut", "cre"), comment = "Package maintainer, responsible for correspondence"),

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# cancensus 0.5.7
2+
3+
- fix issue with path names not quoted properly when downoading and unpacking geosuite data
4+
- support versions in WDS data, in paricular for federal electoral districts
5+
16
# cancensus 0.5.6
27

38
- fix issue when using named vectors to query data for non-existent geographies, return NULL in this case instead of throwing error

R/cancensus.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#' @param level The census aggregation level to retrieve, defaults to \code{"Regions"}. One of \code{"Regions"}, \code{"PR"}, \code{"CMA"}, \code{"CD"}, \code{"CSD"}, \code{"CT"}, \code{"DA"}, \code{"EA"} (for 1996), or \code{"DB"} (for 2001-2016).
1313
#' @param vectors An R vector containing the CensusMapper variable names of the census variables to download. If no vectors are specified only geographic data will get downloaded.
1414
#' @param geo_format By default is set to \code{NA} and appends no geographic information. To include geographic information with census data, specify one of either \code{"sf"} to return an \code{\link[sf]{sf}} object (requires the \code{sf} package) or \code{"sp"} to return a \code{\link[sp]{SpatialPolygonsDataFrame-class}} object (requires the \code{rgdal} package). If user requests geo-spatial data and neither package is available, a context menu will prompt to install the \code{sf} package.
15-
#' @param resolution Resolution of the geographic data. {cancensus} will download simplified geometries by default. For lower level geometries like DB or DA this will be very close to the high resolution data.
15+
#' @param resolution Resolution of the geographic data. By default simplified geometries will be download. For lower level geometries like DB or DA this will be very close to the high resolution data.
1616
#' Simplification generally increases as the geographic aggregation level increases.
1717
#' If high resolution geometries are required
1818
#' then this option can be set to 'high'. By default this setting is set to \code{'simplified'}.

R/geo_suite.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ get_statcan_geo_suite <- function(level,census_year="2021",refresh=FALSE){
4545
options(timeout=old_timeout)
4646
if (!dir.exists(path)) dir.create(path)
4747
if (Sys.info()[['sysname']]=="Darwin") {
48-
system(paste0("ditto -V -x -k --sequesterRsrc --rsrc ",tmp," ",path))
48+
system(paste0("ditto -V -x -k --sequesterRsrc --rsrc '",tmp,"' '",path,"'"))
4949
} else {
5050
utils::unzip(tmp,exdir = path)
5151
}

R/wds.R

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#' @param census_year census year to get the data for, right now only 2021 is supported
88
#' @param level geographic level to return the data for, valid choices are
99
#' "PR","CD","CMACA","CSD","CT","ADA","DA","ER","FED","DPL","POPCNTR", "FSA"
10+
#' @param version optionally specify a version of the data to download. For example, for FED level data, version 1.3 will
11+
#' access the 2013 represenation order, whereas version 2.0 will access the 2023 representation order. By default the latest
12+
#' available version is accessed.
1013
#' @param refresh default is `FALSE` will refresh the temporary cache if `TRUE`
1114
#' @return tibble with the metadata
1215
#'
@@ -16,7 +19,7 @@
1619
#' get_statcan_wds_metadata(census_year="2021",level="FED")
1720
#' }
1821
#' @export
19-
get_statcan_wds_metadata <- function(census_year,level,refresh=FALSE){
22+
get_statcan_wds_metadata <- function(census_year,level,version=NULL,refresh=FALSE){
2023
valid_census_years <- c("2021")
2124
valid_levels <- c("PR","CD","CMACA","CSD","CT","ADA","DA","ER","FED","DPL","POPCNTR","FSA")
2225
if (!(census_year %in% valid_census_years)) {
@@ -25,7 +28,9 @@ get_statcan_wds_metadata <- function(census_year,level,refresh=FALSE){
2528
if (!(level %in% valid_levels)) {
2629
stop(paste0("Level must be one of ",paste0(valid_levels,collapse = ", "),"."))
2730
}
28-
meta_url <- paste0("https://api.statcan.gc.ca/census-recensement/profile/sdmx/rest/dataflow/STC_CP/DF_",level,"?references=all")
31+
meta_url <- paste0("https://api.statcan.gc.ca/census-recensement/profile/sdmx/rest/dataflow/STC_CP/DF_",level,
32+
ifelse(is.null(version),"",paste0("/",version)),
33+
"?references=all")
2934
metadata_tempfile <- file.path(tempdir(),paste0("census_wds_metadata_",digest::digest(meta_url),".sdmx"))
3035
if (refresh || !file.exists(metadata_tempfile)) {
3136
utils::download.file(meta_url,metadata_tempfile)
@@ -67,6 +72,9 @@ get_statcan_wds_metadata <- function(census_year,level,refresh=FALSE){
6772
#' level can be queried via `get_statcan_wds_metadata()`.
6873
#' @param members list of Member IOs to download data for. By default all characteristics are downloaded. Valid
6974
#' Member IDs and their descriptions can be queried via the `get_statcan_wds_metadata()` call.
75+
#' @param version optionally specify a version of the data to download. For example, for FED level data, version 1.3 will
76+
#' access the 2013 represenation order, whereas version 2.0 will access the 2023 representation order. By default the latest
77+
#' available version is accessed.
7078
#' @param gender optionally query data for only one gender. By default this queries data for all genders, possible
7179
#' values are "Total", "Male", "Female" to only query total data, or for males only or for females only.
7280
#' @param language specify language for geography and characteristic names that get added, valid choices are "en" and "fr"
@@ -81,6 +89,7 @@ get_statcan_wds_metadata <- function(census_year,level,refresh=FALSE){
8189
#' @export
8290
get_statcan_wds_data <- function(DGUIDs,
8391
members = NULL,
92+
version= NULL,
8493
gender="All",
8594
language="en",
8695
refresh=FALSE) {
@@ -102,7 +111,7 @@ get_statcan_wds_data <- function(DGUIDs,
102111
gender <- c("All"="","Total"="1","Male"="2","Female"="3")[[gender]]
103112
dguid_string <- paste0(DGUIDs,collapse="+")
104113
member_string <- paste0(members,collapse = "+")
105-
add=paste0("DF_",level,"/A5.",dguid_string,".",gender,".",member_string,".1")
114+
add=paste0("DF_",level,ifelse(is.null(version),"",paste0(",",version)),"/A5.",dguid_string,".",gender,".",member_string,".1")
106115
wds_data_tempfile <- file.path(tempdir(),paste0("wds_data_",digest::digest(add),".csv"))
107116
if (!file.exists(wds_data_tempfile)) {
108117
response <- httr::GET(paste0(url,",",add),
@@ -114,7 +123,7 @@ get_statcan_wds_data <- function(DGUIDs,
114123
stop(paste0("Invalid request.\n",httr::content(response)))
115124
}
116125
census_year <- "2021"
117-
meta_data <- get_statcan_wds_metadata(census_year,level,refresh = refresh)
126+
meta_data <- get_statcan_wds_metadata(census_year,level=level,version = version,refresh = refresh)
118127

119128
levels <- meta_data %>%
120129
dplyr::filter(.data$`Codelist ID`=="CL_GEO_LEVEL")

README.md

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# cancensus
22

3-
[![R build status](https://github.com/mountainMath/cancensus/workflows/R-CMD-check/badge.svg)](https://github.com/mountainMath/cancensus/actions)
3+
[![R-CMD-check](https://github.com/mountainMath/cancensus/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/mountainMath/cancensus/actions/workflows/R-CMD-check.yaml)
44
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/cancensus)](https://cran.r-project.org/package=cancensus)
55
[![CRAN_Downloads_Badge](https://cranlogs.r-pkg.org/badges/cancensus)](https://cranlogs.r-pkg.org/badges/cancensus)
66

@@ -51,7 +51,7 @@ Starting with version 0.5.2 **cancensus** will automatically check if for data t
5151

5252
### Currently available datasets
5353

54-
**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](https://www12.statcan.gc.ca/census-recensement/2021/ref/prodserv/release-diffusion-eng.cfm).
54+
**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.
5555

5656
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.
5757

@@ -105,14 +105,17 @@ We'd love to feature examples of work or projects that use cancensus.
105105

106106

107107
### Related packages
108-
This package is designed to play well with other Canadian data packages, in particular
108+
The cancensus package is designed for working with Canadian Census data. In addition to Census data, Statistics Canada provides access to a vast [socio-economic data repository](https://www150.statcan.gc.ca/n1/en/type/data) with thousands of data tables available for public access.
109+
110+
The [cansim package](https://mountainmath.github.io/cansim/index.html) is designed to retrieve and work with public Statistics Canada data tables. The cansim prepares retrieved data tables as analysis-ready tidy dataframes and provides a number of convenience tools and functions to make it easier to work with Statistics Canada data. It is available on CRAN and on [Github](https://github.com/mountainMath/cancensus). Data retrieved via the cansim package can be linked to census data via the `GeoUID` field.
109111

110-
* [**tongfen**](https://mountainmath.github.io/tongfen/index.html), which solves the problem of making data across several census years comparable,
111-
* [**cansim**](https://mountainmath.github.io/cansim/index.html), which accesses regular StatCan tables and can be linked to census geographies via the `GeoUID`,and
112-
* [**cmhc**](https://mountainmath.github.io/cmhc/index.html), which accesses CMHC data and can be linked to census geographies via the `GeoUID`.
112+
The [tongfen package](https://mountainmath.github.io/tongfen/index.html) automates the task of obtaining census variables from different census years on a common geography. It is available on [Github](https://github.com/mountainMath/tongfen).
113+
114+
The [**cmhc**](https://mountainmath.github.io/cmhc/index.html) package, which accesses CMHC data on the housing in Canada and can be linked to census geographies via the `GeoUID`.
113115

114116
Taken together these packages offer a seamless view into important Canadian data.
115117

118+
### International census data
116119
There are several other jurisdiction where census data is available via R packages, including
117120

118121
* US: [tidycensus](https://walker-data.com/tidycensus/) and [tigris](https://github.com/walkerke/tigris)
@@ -139,7 +142,7 @@ There are several other jurisdiction where census data is available via R packag
139142
If you wish to cite cancensus:
140143

141144
von Bergmann, J., Aaron Jacobs, Dmitry Shkolnik (2022). cancensus: R package to
142-
access, retrieve, and work with Canadian Census data and geography. v0.5.6.
145+
access, retrieve, and work with Canadian Census data and geography. v0.5.7.
143146

144147

145148
A BibTeX entry for LaTeX users is
@@ -148,19 +151,11 @@ A BibTeX entry for LaTeX users is
148151
author = {Jens {von Bergmann} and Dmitry Shkolnik and Aaron Jacobs},
149152
title = {cancensus: R package to access, retrieve, and work with Canadian Census data and geography},
150153
year = {2022},
151-
note = {R package version 0.5.6},
154+
note = {R package version 0.5.7},
152155
url = {https://mountainmath.github.io/cancensus/}
153156
}
154157
```
155-
### Related packages
156158

157-
The cancensus package is designed for working with Canadian Census data. In addition to Census data, Statistics Canada provides access to a vast [socio-economic data repository](https://www150.statcan.gc.ca/n1/en/type/data) with thousands of data tables available for public access.
158-
159-
The [cansim package](https://mountainmath.github.io/cansim/index.html) is designed to retrieve and work with public Statistics Canada data tables. The cansim prepares retrieved data tables as analysis-ready tidy dataframes and provides a number of convenience tools and functions to make it easier to work with Statistics Canada data. It is available on CRAN and on [Github](https://github.com/mountainMath/cancensus).
160-
161-
Data downloaded through the cansim package that comes with standard geographic attributes will typically share a common geographic ID that can be matched to Census data.
162-
163-
The [tongfen package](https://mountainmath.github.io/tongfen/index.html) automates the task of obtaining census variables from different census years on a common geography. It is available on [Github](https://github.com/mountainMath/tongfen).
164159

165160
### Statistics Canada Attribution
166161

cancensus.Rproj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Version: 1.0
2+
3+
RestoreWorkspace: Default
4+
SaveWorkspace: Default
5+
AlwaysSaveHistory: Default
6+
7+
EnableCodeIndexing: Yes
8+
UseSpacesForTab: Yes
9+
NumSpacesForTab: 2
10+
Encoding: UTF-8
11+
12+
RnwWeave: knitr
13+
LaTeX: pdfLaTeX
14+
15+
AutoAppendNewline: Yes
16+
StripTrailingWhitespace: Yes
17+
18+
BuildType: Package
19+
PackageUseDevtools: Yes
20+
PackageInstallArgs: --no-multiarch --with-keep.source

cran-comments.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# cancensus 0.5.7
2+
- fix issue with path names not quoted properly when downoading and unpacking geosuite data
3+
- support versions in WDS data, in paricular for federal electoral districts
4+
15
# cancensus 0.5.6
26
- fix issue when using named vectors to query data for non-existent geographies, return NULL in this case instead of throwing error
37
- fix problem with population centre geographic data download

docs/404.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)