|
8 | 8 | #' @param default_month The default month that should be used when creating Date objects for annual data (default set to "01") |
9 | 9 | #' @param default_day The default day of the month that should be used when creating Date objects for monthly data (default set to "01") |
10 | 10 | #' @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}). |
12 | 13 | #' @param cansimTableNumber (Optional) Only needed when operating on results of SQLite connections. |
13 | 14 | #' @param internal (Optional) Flag to indicate that this function is called internally. |
14 | 15 | #' |
@@ -136,6 +137,9 @@ normalize_cansim_values <- function(data, replacement_value="val_norm", normaliz |
136 | 137 | fields= gsub(classification_prefix,"",names(data)[grepl(classification_prefix,names(data))]) |
137 | 138 | } |
138 | 139 |
|
| 140 | + if (factors) { #override for consistency |
| 141 | + strip_classification_code=TRUE |
| 142 | + } |
139 | 143 |
|
140 | 144 | if (strip_classification_code){ |
141 | 145 | for (field in fields) { |
@@ -203,7 +207,7 @@ normalize_cansim_values <- function(data, replacement_value="val_norm", normaliz |
203 | 207 | } |
204 | 208 |
|
205 | 209 | # 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)) { |
207 | 211 | data <- data %>% |
208 | 212 | relocate(!!as.name(replacement_value_string),.after=!!as.name(value_string)) |
209 | 213 | } |
@@ -489,6 +493,9 @@ get_cansim <- function(cansimTableNumber, language="english", refresh=FALSE, tim |
489 | 493 | data <- readRDS(file=data_path) |
490 | 494 | } |
491 | 495 |
|
| 496 | + attr(data,"language") <- cleaned_language |
| 497 | + attr(data,"cansimTableNumber") <- cleaned_number |
| 498 | + |
492 | 499 | if (!is.null(getOption("cansim.debug"))) message('Initiating normalization') |
493 | 500 | data <- data %>% |
494 | 501 | normalize_cansim_values(replacement_value = "val_norm", factors = factors, |
|
0 commit comments