@@ -41,7 +41,7 @@ table_base_path <- function(cansimTableNumber) {
4141
4242file_path_for_table_language <- function (cansimTableNumber , language ){
4343 language <- cleaned_ndm_language(language )
44- if (is.na(language )) stop(paste0(" Unkown Lanaguage " ,language ))
44+ if (is.na(language )) stop(paste0(" Unkown Lanaguage " ,language ), call. = FALSE )
4545 base_table <- naked_ndm_table_number(cansimTableNumber )
4646 file.path(paste0(base_table ," -" ,language ))
4747}
@@ -91,7 +91,7 @@ get_with_timeout_retry <- function(url,timeout=200,retry=3,path=NA,warn_only=FAL
9191 " Statistics Canada has a history of failty SSL certificats on their API,\n " ,
9292 " if you are reasonably sure that your connection is not getting hijacked you\n " ,
9393 " can disable peer checking for the duration of the R session by typing\n\n " ,
94- " httr::set_config(httr::config(ssl_verifypeer=0,ssl_verifystatus=0))" ," \n\n " ," into the console." )
94+ " httr::set_config(httr::config(ssl_verifypeer=0,ssl_verifystatus=0))" ," \n\n " ," into the console." , call. = FALSE )
9595 }
9696 if (retry > 0 ) {
9797 message(" Got timeout from StatCan, trying again" )
@@ -141,7 +141,7 @@ post_with_timeout_retry <- function(url,body,timeout=200,retry=3,warn_only=FALSE
141141 " Statistics Canada has a history of failty SSL certificats on their API,\n " ,
142142 " if you are reasonably sure that your connection is not getting hijacked you\n " ,
143143 " can disable peer checking for the duration of the R session by typing\n\n " ,
144- " httr::set_config(httr::config(ssl_verifypeer=0,ssl_verifystatus=0))" ," \n\n " ," into the console." )
144+ " httr::set_config(httr::config(ssl_verifypeer=0,ssl_verifystatus=0))" ," \n\n " ," into the console." , call. = FALSE )
145145 }
146146 if (retry > 0 ) {
147147 message(" Got timeout from StatCan, trying again" )
@@ -185,23 +185,6 @@ short_prov.en <- c(
185185 " Canada" = " CAN"
186186)
187187
188- # short_prov.fr <- c(
189- # "Colombie-Britannique"="BC",
190- # "Alberta"="AB",
191- # "Saskatchewan"="SK",
192- # "Manitoba"="MB",
193- # "Ontario"="ON",
194- # "Qu\U00E9bec"="QC",
195- # "Nouveau-Brunswick"="NB",
196- # "\u00CEle-du-Prince-\U00C9douard"="PE",
197- # "Nouvelle-\U00C9cosse"="NS",
198- # "Terre-Neuve-et-Labrador"="NL",
199- # "Yukon"="YT",
200- # "Territoires du Nord-Ouest"="NT",
201- # "Nunavut"="NU",
202- # "Territoires du Nord-Ouest incluant Nunavut"="NTNU",
203- # "Canada"="CAN"
204- # )
205188
206189short_prov.fr <- setNames(c(
207190 " BC" ,
@@ -290,7 +273,7 @@ get_cansim_code_set <- function(code_set=c("scalar", "frequency", "symbol", "sta
290273 refresh = FALSE ){
291274 code_sets <- c(" scalar" , " frequency" , " symbol" , " status" , " uom" , " survey" , " subject" , " wdsResponseStatus" )
292275 if (length(code_set )!= 1 | ! (code_set %in% code_sets )) {
293- stop(paste0(" Invalid code set, code_set must be one of " ,paste0(code_sets ,collapse = " , " )))
276+ stop(paste0(" Invalid code set, code_set must be one of " ,paste0(code_sets ,collapse = " , " )), call. = FALSE )
294277 }
295278 path = file.path(tempdir()," cansim_code_sets.Rmd" )
296279 if (refresh | ! file.exists(path )) {
@@ -301,7 +284,7 @@ get_cansim_code_set <- function(code_set=c("scalar", "frequency", "symbol", "sta
301284 saveRDS(content ,path )
302285 } else {
303286 warning(" Problem downloading code sets." )
304- stop(httr :: content(r ))
287+ stop(httr :: content(r ), call. = FALSE )
305288 }
306289 } else {
307290 content <- readRDS(path )
@@ -410,7 +393,7 @@ format_file_size <- function (x, units = "b", standard = "auto", digits = 1L, ..
410393 else if (endsWith(units , " b" ))
411394 standard <- " legacy"
412395 else if (units == " kB" )
413- stop(" For SI units, specify 'standard = \" SI\" '" )
396+ stop(" For SI units, specify 'standard = \" SI\" '" , call. = FALSE )
414397 }
415398 }
416399 base <- known_bases [[standard ]]
@@ -426,7 +409,7 @@ format_file_size <- function (x, units = "b", standard = "auto", digits = 1L, ..
426409 1L
427410 if (is.na(power ))
428411 stop(gettextf(" Unit \" %s\" is not part of standard \" %s\" " ,
429- sQuote(units ), sQuote(standard )), domain = NA )
412+ sQuote(units ), sQuote(standard )), domain = NA , call. = FALSE )
430413 }
431414 unit <- units_map [power + 1L ]
432415 if (power == 0 && standard == " legacy" )
@@ -579,5 +562,19 @@ normalize_coordinates <- function(coordinates){
579562
580563}
581564
582-
565+ get_robust_cache_path <- function (cache_path ) {
566+ if (is.null(cache_path ) || cache_path == " " ) {
567+ cache_path <- Sys.getenv(" CANSIM_CACHE_PATH" )
568+ if (cache_path == " " ) cache_path <- getOption(" cansim.cache_path" ,default = " " )
569+ if (cache_path == " " ) {
570+ cache_path <- file.path(tempdir()," cansim_cache" )
571+ if (! dir.exists(cache_path )) dir.create(cache_path )
572+ message(cansim_no_cache_path_message )
573+ }
574+ }
575+ if (! dir.exists(cache_path )) {
576+ stop(" Cache path " ,cache_path ," does not exist, please create it first." ,call. = FALSE )
577+ }
578+ cache_path
579+ }
583580
0 commit comments