Skip to content

Commit fdc9943

Browse files
authored
Merge pull request #131 from mountainMath/0.4.1
fix problem with parsing census tables, add unit test
2 parents 26bd899 + 574b35e commit fdc9943

72 files changed

Lines changed: 176 additions & 95 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.

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: cansim
22
Type: Package
33
Title: Accessing Statistics Canada Data Table and Vectors
4-
Version: 0.4
4+
Version: 0.4.1
55
Authors@R: c(
66
person("Jens", "von Bergmann", email = "jens@mountainmath.ca", role = c("aut","cre")),
77
person("Dmitry", "Shkolnik", email = "shkolnikd@gmail.com", role = c("aut")))

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# cansim 0.4.1
2+
## Minor changes
3+
* fix problem with parsing census data tables
4+
* fix problem with converting to factors when classification codes are attached.
5+
16
# cansim 0.4
27
## Major changes
38
* add support for local caching in parquet and feather formats

R/cansim.R

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
#' @param default_month The default month that should be used when creating Date objects for annual data (default set to "01")
99
#' @param default_day The default day of the month that should be used when creating Date objects for monthly data (default set to "01")
1010
#' @param factors (Optional) Logical value indicating if dimensions should be converted to factors. (Default set to \code{TRUE}).
11-
#' @param strip_classification_code (strip_classification_code) Logical value indicating if classification code should be stripped from names. (Default set to \code{false}).
11+
#' @param strip_classification_code (strip_classification_code) Logical value indicating if classification code should be stripped
12+
#' from names. (Default set to \code{FALSE}, if \code{factors=TRUE} this is overridden and set to \code{TRUE}).
1213
#' @param cansimTableNumber (Optional) Only needed when operating on results of SQLite connections.
1314
#' @param internal (Optional) Flag to indicate that this function is called internally.
1415
#'
@@ -136,6 +137,9 @@ normalize_cansim_values <- function(data, replacement_value="val_norm", normaliz
136137
fields= gsub(classification_prefix,"",names(data)[grepl(classification_prefix,names(data))])
137138
}
138139

140+
if (factors) { #override for consistency
141+
strip_classification_code=TRUE
142+
}
139143

140144
if (strip_classification_code){
141145
for (field in fields) {
@@ -203,7 +207,7 @@ normalize_cansim_values <- function(data, replacement_value="val_norm", normaliz
203207
}
204208

205209
# column order
206-
if (replacement_value_string != value_string) {
210+
if (replacement_value_string != value_string && replacement_value_string %in% names(data) && value_string %in% names(data)) {
207211
data <- data %>%
208212
relocate(!!as.name(replacement_value_string),.after=!!as.name(value_string))
209213
}
@@ -489,6 +493,9 @@ get_cansim <- function(cansimTableNumber, language="english", refresh=FALSE, tim
489493
data <- readRDS(file=data_path)
490494
}
491495

496+
attr(data,"language") <- cleaned_language
497+
attr(data,"cansimTableNumber") <- cleaned_number
498+
492499
if (!is.null(getOption("cansim.debug"))) message('Initiating normalization')
493500
data <- data %>%
494501
normalize_cansim_values(replacement_value = "val_norm", factors = factors,

R/cansim_members.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ get_cansim_members <- function(cansimTableNumber, language="english",
2828
})
2929

3030
members %>%
31-
seq_along() %>%
31+
#seq_along() %>%
3232
lapply(\(i,el,n){
3333

3434
})

R/cansim_parquet.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ collect_and_normalize <- function(connection,
518518
cansimTableNumber <- attr(connection,"cansimTableNumber")
519519
language <- attr(connection,"language")
520520

521-
if ((is.null(language)||is.null(cansimTableNumber))&& ("arrow_dplyr_query" %in% class(connection))) {
521+
if ((is.null(language)||is.null(cansimTableNumber))&& ("arrow_dplyr_query" %in% class(connection) || "ArrowObject" %in% class(connection))) {
522522
md <- arrow::schema(connection)$metadata
523523
cansimTableNumber <- md$cansimTableNumber
524524
language <- md$language
@@ -536,7 +536,7 @@ collect_and_normalize <- function(connection,
536536
attr(data,"cansimTableNumber") <- cansimTableNumber
537537

538538
if (disconnect) disconnect_cansim_sqlite(connection)
539-
} else if ("arrow_dplyr_query" %in% class(connection)){
539+
} else if ("arrow_dplyr_query" %in% class(connection) || "ArrowObject" %in% class(connection)){
540540
data <- connection %>%
541541
dplyr::as_tibble()
542542
attr(data,"language") <- language

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ If you want to get in touch, we are pretty good at responding via email or via t
231231

232232
If you wish to cite the `cansim` package in your work:
233233

234-
von Bergmann, J., Dmitry Shkolnik (2024). cansim: functions and convenience tools for accessing Statistics Canada data tables. v0.4. DOI: 10.32614/CRAN.package.cansim
234+
von Bergmann, J., Dmitry Shkolnik (2024). cansim: functions and convenience tools for accessing Statistics Canada data tables. v0.4.1. DOI: 10.32614/CRAN.package.cansim
235235

236236
A BibTeX entry for LaTeX users is
237237

@@ -241,7 +241,7 @@ A BibTeX entry for LaTeX users is
241241
title = {cansim: functions and convenience tools for accessing Statistics Canada data tables},
242242
year = {2025},
243243
doi = {10.32614/CRAN.package.cansim},
244-
note = {R package version 0.4},
244+
note = {R package version 0.4.1},
245245
url = {https://mountainmath.github.io/cansim/}
246246
}
247247
```

cran-comments.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,9 @@ There were no ERRORs or WARNINGs or NOTEs.
125125
* fix problem with inconsistent type parsing of notes
126126
* better support for french language when accessing data by vector or coordinate
127127
* tests
128+
129+
# cansim 0.4.1
130+
## Minor changes
131+
* fix problem with parsing census data tables
132+
* fix problem with converting to factors when classification codes are attached.
133+

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.

docs/LICENSE-text.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.

docs/LICENSE.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)