├── _pkgdown.yml ├── vignettes ├── .gitignore ├── vignettes.Rmd └── statCanR.Rmd ├── LICENSE ├── .gitignore ├── man ├── figures │ ├── shiny.png │ └── README-pressure-1.png ├── statcan_download_data.Rd ├── statcan_search.Rd └── statcan_data.Rd ├── docs ├── reference │ ├── Rplot001.png │ ├── figures │ │ ├── shiny.png │ │ └── README-pressure-1.png │ ├── libs │ │ ├── dt-core-1.12.1 │ │ │ └── css │ │ │ │ └── jquery.dataTables.extra.css │ │ ├── dt-core-1.13.4 │ │ │ └── css │ │ │ │ └── jquery.dataTables.extra.css │ │ ├── crosstalk-1.2.0 │ │ │ ├── css │ │ │ │ └── crosstalk.min.css │ │ │ └── scss │ │ │ │ └── crosstalk.scss │ │ └── datatables-css-0.0.0 │ │ │ └── datatables-crosstalk.css │ ├── index.html │ ├── statcan_data.html │ ├── statcan_download_data.html │ └── statcan_search.html ├── pkgdown.yml ├── articles │ ├── statcanR_example1_files │ │ ├── figure-html │ │ │ ├── unnamed-chunk-4-1.png │ │ │ └── unnamed-chunk-5-1.png │ │ ├── dt-core-1.12.1 │ │ │ └── css │ │ │ │ └── jquery.dataTables.extra.css │ │ ├── crosstalk-1.2.0 │ │ │ ├── css │ │ │ │ └── crosstalk.min.css │ │ │ └── scss │ │ │ │ └── crosstalk.scss │ │ └── datatables-css-0.0.0 │ │ │ └── datatables-crosstalk.css │ ├── statcanR_example2_files │ │ ├── figure-html │ │ │ ├── unnamed-chunk-4-1.png │ │ │ ├── unnamed-chunk-5-1.png │ │ │ └── unnamed-chunk-6-1.png │ │ ├── dt-core-1.12.1 │ │ │ └── css │ │ │ │ └── jquery.dataTables.extra.css │ │ ├── crosstalk-1.2.0 │ │ │ ├── css │ │ │ │ └── crosstalk.min.css │ │ │ └── scss │ │ │ │ └── crosstalk.scss │ │ └── datatables-css-0.0.0 │ │ │ └── datatables-crosstalk.css │ ├── index.html │ ├── vignettes.html │ └── statCanR.html ├── link.svg ├── sitemap.xml ├── bootstrap-toc.css ├── docsearch.js ├── pkgdown.js ├── LICENSE-text.html ├── bootstrap-toc.js ├── 404.html ├── LICENSE.html ├── authors.html ├── news │ └── index.html ├── pkgdown.css └── docsearch.css ├── CRAN-SUBMISSION ├── .travis.yml ├── .Rbuildignore ├── NAMESPACE ├── statcanR3.Rproj ├── cran-comments.md ├── NEWS.md ├── DESCRIPTION ├── LICENSE.md ├── appveyor.yml ├── R ├── statcan_search.R └── statCanR.R ├── inst ├── README.md └── README.Rmd ├── CITATION.cff └── README.md /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | destination: docs 2 | -------------------------------------------------------------------------------- /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | *.R 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2020 2 | COPYRIGHT HOLDER: Thierry Warin ; Romain Le Duc 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | inst/doc 6 | -------------------------------------------------------------------------------- /man/figures/shiny.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warint/statcanR/HEAD/man/figures/shiny.png -------------------------------------------------------------------------------- /docs/reference/Rplot001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warint/statcanR/HEAD/docs/reference/Rplot001.png -------------------------------------------------------------------------------- /CRAN-SUBMISSION: -------------------------------------------------------------------------------- 1 | Version: 0.2.6 2 | Date: 2023-08-16 20:56:20 UTC 3 | SHA: e54f7ce1b24d3acb91195bdf6c628da52fbc6bd7 4 | -------------------------------------------------------------------------------- /docs/reference/figures/shiny.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warint/statcanR/HEAD/docs/reference/figures/shiny.png -------------------------------------------------------------------------------- /man/figures/README-pressure-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warint/statcanR/HEAD/man/figures/README-pressure-1.png -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # R for travis: see documentation at https://docs.travis-ci.com/user/languages/r 2 | 3 | language: R 4 | cache: packages 5 | -------------------------------------------------------------------------------- /docs/reference/figures/README-pressure-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warint/statcanR/HEAD/docs/reference/figures/README-pressure-1.png -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: 2.19.2 2 | pkgdown: 2.0.7 3 | pkgdown_sha: ~ 4 | articles: 5 | statCanR: statCanR.html 6 | vignettes: vignettes.html 7 | last_built: 2023-08-14T13:51Z 8 | 9 | -------------------------------------------------------------------------------- /docs/articles/statcanR_example1_files/figure-html/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warint/statcanR/HEAD/docs/articles/statcanR_example1_files/figure-html/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /docs/articles/statcanR_example1_files/figure-html/unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warint/statcanR/HEAD/docs/articles/statcanR_example1_files/figure-html/unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /docs/articles/statcanR_example2_files/figure-html/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warint/statcanR/HEAD/docs/articles/statcanR_example2_files/figure-html/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /docs/articles/statcanR_example2_files/figure-html/unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warint/statcanR/HEAD/docs/articles/statcanR_example2_files/figure-html/unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /docs/articles/statcanR_example2_files/figure-html/unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warint/statcanR/HEAD/docs/articles/statcanR_example2_files/figure-html/unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^README\.Rmd$ 4 | ^_pkgdown\.yml$ 5 | ^docs$ 6 | ^pkgdown$ 7 | ^\.travis\.yml$ 8 | ^appveyor\.yml$ 9 | ^codecov\.yml$ 10 | ^cran-comments\.Rmd$ 11 | ^CRAN-RELEASE$ 12 | ^cran-comments\.md$ 13 | ^LICENSE\.md$ 14 | ^CRAN-SUBMISSION$ 15 | ^CITATION\.cff$ 16 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(statcan_data) 4 | export(statcan_download_data) 5 | export(statcan_search) 6 | import(DT) 7 | import(curl) 8 | import(dplyr) 9 | import(ggplot2) 10 | import(qpdf) 11 | import(qs) 12 | import(reshape2) 13 | import(tibble) 14 | importFrom(data.table,fread) 15 | importFrom(data.table,setDF) 16 | importFrom(httr,http_error) 17 | -------------------------------------------------------------------------------- /vignettes/vignettes.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "vignettes" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{vignettes} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | ```{r, include = FALSE} 11 | knitr::opts_chunk$set( 12 | collapse = TRUE, 13 | comment = "#>" 14 | ) 15 | ``` 16 | 17 | ```{r setup} 18 | library(statcanR) 19 | ``` 20 | -------------------------------------------------------------------------------- /statcanR3.Rproj: -------------------------------------------------------------------------------- 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: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | BuildType: Package 16 | PackageUseDevtools: Yes 17 | PackageInstallArgs: --no-multiarch --with-keep.source 18 | PackageCheckArgs: --as-cran 19 | PackageRoxygenize: rd,collate,namespace,vignette 20 | -------------------------------------------------------------------------------- /man/statcan_download_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/statCanR.R 3 | \name{statcan_download_data} 4 | \alias{statcan_download_data} 5 | \title{statcanR download data function} 6 | \usage{ 7 | statcan_download_data(tableNumber, lang) 8 | } 9 | \arguments{ 10 | \item{tableNumber}{The table number of the Statistics Canada data table} 11 | 12 | \item{lang}{The language wanted} 13 | } 14 | \value{ 15 | The output will be a data table and csv file representing the data associated with the chosen table number. 16 | } 17 | \description{ 18 | statcanR download data function 19 | } 20 | \examples{ 21 | mydata <- statcan_data('27-10-0014-01', 'eng') 22 | } 23 | -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | ## Resubmission 2 | 3 | This is a resubmission to correct things ask by CRAN team. In this version I have: 4 | 5 | 6 | * Fix statcan_search function and remove top level code so internet connection is not needed to install the package 7 | 8 | 9 | 10 | ## Resubmission 11 | 12 | This is a resubmission (update). In this version I have : 13 | 14 | * Fix the version to a serious number from 0.2.3.9000 to 0.2.3 and corrected invalid url from readme.md 15 | 16 | ## Test environments 17 | * local OS X install, R 3.6.1 18 | * ubuntu 14.04 (on travis-ci), R 3.6.1 19 | * microsoft (on appveyor), R 3.6.1 20 | * win-builder (devel and release) 21 | 22 | ## R CMD check results 23 | 24 | 0 errors | 0 warnings | 0 note 25 | 26 | * This is an update. 27 | 28 | ## Downstream dependencies 29 | There are currently no downstream dependencies for this package. -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # statcanR 0.2.6 2 | 3 | * fix server issue 4 | 5 | # statcanR 0.2.5 6 | 7 | * We have corrected statcan_search() function by removing top level code. You can now install statcanR package without an internet connection 8 | 9 | # statcanR 0.2.4 10 | 11 | * we have added the function statcan_search() to identify economic data tables available on Statistics Canada's website. 12 | 13 | # statcanR 0.2.3 14 | 15 | * we have modified the function to get an informative message if the table is not available instead of having an error message. 16 | 17 | # statcanR 0.2.2 18 | 19 | * we replaced utils::read.csv by readr::read_csv to fix a random bug with some metadata tables. 20 | 21 | # statcanR 0.2.1 22 | 23 | * In this version, we have changed the name of the functions by withdrawing the sqs mentions. The old functions will remain available until the next update (deprecated). 24 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: statcanR 2 | Type: Package 3 | Title: Client for Statistics Canada's Open Economic Data 4 | Version: 0.2.9000 5 | Authors@R: c( 6 | person("Thierry", "Warin", email = "thierry.warin@hec.ca", role =c("aut", "cre"), comment = c(ORCID = "0000-0002-5921-3428") ), 7 | person("Romain", "Le Duc", role = "aut")) 8 | Description: An easy connection with R to Statistics Canada's Web Data Service. Open economic data (formerly known as CANSIM tables, now identified by Product IDs (PID)) are accessible as a data frame, directly in the user's R environment. 9 | Warin, Le Duc (2019) . 10 | License: MIT + file LICENSE 11 | Encoding: UTF-8 12 | LazyData: true 13 | RoxygenNote: 7.2.3 14 | Suggests: 15 | knitr, 16 | rmarkdown, 17 | testthat (>= 3.0.0) 18 | VignetteBuilder: knitr 19 | Imports: 20 | data.table, 21 | dplyr, 22 | ggplot2, 23 | reshape2, 24 | qs, 25 | qpdf, 26 | DT, 27 | curl, 28 | httr, 29 | readr, 30 | tibble 31 | URL: https://github.com/warint/statcanR/ 32 | BugReports: https://github.com/warint/statcanR/issues/ 33 | Config/testthat/edition: 3 34 | -------------------------------------------------------------------------------- /docs/sitemap.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | /404.html 5 | 6 | 7 | /LICENSE-text.html 8 | 9 | 10 | /LICENSE.html 11 | 12 | 13 | /articles/index.html 14 | 15 | 16 | /articles/statCanR.html 17 | 18 | 19 | /articles/statcanR_example1.html 20 | 21 | 22 | /articles/statcanR_example2.html 23 | 24 | 25 | /articles/vignettes.html 26 | 27 | 28 | /authors.html 29 | 30 | 31 | /index.html 32 | 33 | 34 | /news/index.html 35 | 36 | 37 | /reference/index.html 38 | 39 | 40 | /reference/statcan_data.html 41 | 42 | 43 | /reference/statcan_download_data.html 44 | 45 | 46 | /reference/statcan_search.html 47 | 48 | 49 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2020 Thierry Warin ; Romain Le Duc 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /docs/reference/libs/dt-core-1.12.1/css/jquery.dataTables.extra.css: -------------------------------------------------------------------------------- 1 | /* Selected rows/cells */ 2 | table.dataTable tr.selected td, table.dataTable td.selected { 3 | background-color: #b0bed9 !important; 4 | } 5 | /* In case of scrollX/Y or FixedHeader */ 6 | .dataTables_scrollBody .dataTables_sizing { 7 | visibility: hidden; 8 | } 9 | 10 | /* The datatables' theme CSS file doesn't define 11 | the color but with white background. It leads to an issue that 12 | when the HTML's body color is set to 'white', the user can't 13 | see the text since the background is white. One case happens in the 14 | RStudio's IDE when inline viewing the DT table inside an Rmd file, 15 | if the IDE theme is set to "Cobalt". 16 | 17 | See https://github.com/rstudio/DT/issues/447 for more info 18 | 19 | This fixes should have little side-effects because all the other elements 20 | of the default theme use the #333 font color. 21 | 22 | TODO: The upstream may use relative colors for both the table background 23 | and the color. It means the table can display well without this patch 24 | then. At that time, we need to remove the below CSS attributes. 25 | */ 26 | div.datatables { 27 | color: #333; 28 | } 29 | -------------------------------------------------------------------------------- /docs/reference/libs/dt-core-1.13.4/css/jquery.dataTables.extra.css: -------------------------------------------------------------------------------- 1 | /* Selected rows/cells */ 2 | table.dataTable tr.selected td, table.dataTable td.selected { 3 | background-color: #b0bed9 !important; 4 | } 5 | /* In case of scrollX/Y or FixedHeader */ 6 | .dataTables_scrollBody .dataTables_sizing { 7 | visibility: hidden; 8 | } 9 | 10 | /* The datatables' theme CSS file doesn't define 11 | the color but with white background. It leads to an issue that 12 | when the HTML's body color is set to 'white', the user can't 13 | see the text since the background is white. One case happens in the 14 | RStudio's IDE when inline viewing the DT table inside an Rmd file, 15 | if the IDE theme is set to "Cobalt". 16 | 17 | See https://github.com/rstudio/DT/issues/447 for more info 18 | 19 | This fixes should have little side-effects because all the other elements 20 | of the default theme use the #333 font color. 21 | 22 | TODO: The upstream may use relative colors for both the table background 23 | and the color. It means the table can display well without this patch 24 | then. At that time, we need to remove the below CSS attributes. 25 | */ 26 | div.datatables { 27 | color: #333; 28 | } 29 | -------------------------------------------------------------------------------- /docs/articles/statcanR_example1_files/dt-core-1.12.1/css/jquery.dataTables.extra.css: -------------------------------------------------------------------------------- 1 | /* Selected rows/cells */ 2 | table.dataTable tr.selected td, table.dataTable td.selected { 3 | background-color: #b0bed9 !important; 4 | } 5 | /* In case of scrollX/Y or FixedHeader */ 6 | .dataTables_scrollBody .dataTables_sizing { 7 | visibility: hidden; 8 | } 9 | 10 | /* The datatables' theme CSS file doesn't define 11 | the color but with white background. It leads to an issue that 12 | when the HTML's body color is set to 'white', the user can't 13 | see the text since the background is white. One case happens in the 14 | RStudio's IDE when inline viewing the DT table inside an Rmd file, 15 | if the IDE theme is set to "Cobalt". 16 | 17 | See https://github.com/rstudio/DT/issues/447 for more info 18 | 19 | This fixes should have little side-effects because all the other elements 20 | of the default theme use the #333 font color. 21 | 22 | TODO: The upstream may use relative colors for both the table background 23 | and the color. It means the table can display well without this patch 24 | then. At that time, we need to remove the below CSS attributes. 25 | */ 26 | div.datatables { 27 | color: #333; 28 | } 29 | -------------------------------------------------------------------------------- /docs/articles/statcanR_example2_files/dt-core-1.12.1/css/jquery.dataTables.extra.css: -------------------------------------------------------------------------------- 1 | /* Selected rows/cells */ 2 | table.dataTable tr.selected td, table.dataTable td.selected { 3 | background-color: #b0bed9 !important; 4 | } 5 | /* In case of scrollX/Y or FixedHeader */ 6 | .dataTables_scrollBody .dataTables_sizing { 7 | visibility: hidden; 8 | } 9 | 10 | /* The datatables' theme CSS file doesn't define 11 | the color but with white background. It leads to an issue that 12 | when the HTML's body color is set to 'white', the user can't 13 | see the text since the background is white. One case happens in the 14 | RStudio's IDE when inline viewing the DT table inside an Rmd file, 15 | if the IDE theme is set to "Cobalt". 16 | 17 | See https://github.com/rstudio/DT/issues/447 for more info 18 | 19 | This fixes should have little side-effects because all the other elements 20 | of the default theme use the #333 font color. 21 | 22 | TODO: The upstream may use relative colors for both the table background 23 | and the color. It means the table can display well without this patch 24 | then. At that time, we need to remove the below CSS attributes. 25 | */ 26 | div.datatables { 27 | color: #333; 28 | } 29 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | # DO NOT CHANGE the "init" and "install" sections below 2 | 3 | # Download script file from GitHub 4 | init: 5 | ps: | 6 | $ErrorActionPreference = "Stop" 7 | Invoke-WebRequest http://raw.github.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1" 8 | Import-Module '..\appveyor-tool.ps1' 9 | 10 | install: 11 | ps: Bootstrap 12 | 13 | cache: 14 | - C:\RLibrary 15 | 16 | environment: 17 | NOT_CRAN: true 18 | # env vars that may need to be set, at least temporarily, from time to time 19 | # see https://github.com/krlmlr/r-appveyor#readme for details 20 | # USE_RTOOLS: true 21 | # R_REMOTES_STANDALONE: true 22 | 23 | # Adapt as necessary starting from here 24 | 25 | build_script: 26 | - travis-tool.sh install_deps 27 | 28 | test_script: 29 | - travis-tool.sh run_tests 30 | 31 | on_failure: 32 | - 7z a failure.zip *.Rcheck\* 33 | - appveyor PushArtifact failure.zip 34 | 35 | artifacts: 36 | - path: '*.Rcheck\**\*.log' 37 | name: Logs 38 | 39 | - path: '*.Rcheck\**\*.out' 40 | name: Logs 41 | 42 | - path: '*.Rcheck\**\*.fail' 43 | name: Logs 44 | 45 | - path: '*.Rcheck\**\*.Rout' 46 | name: Logs 47 | 48 | - path: '\*_*.tar.gz' 49 | name: Bits 50 | 51 | - path: '\*_*.zip' 52 | name: Bits 53 | -------------------------------------------------------------------------------- /docs/reference/libs/crosstalk-1.2.0/css/crosstalk.min.css: -------------------------------------------------------------------------------- 1 | .container-fluid.crosstalk-bscols{margin-left:-30px;margin-right:-30px;white-space:normal}body>.container-fluid.crosstalk-bscols{margin-left:auto;margin-right:auto}.crosstalk-input-checkboxgroup .crosstalk-options-group .crosstalk-options-column{display:inline-block;padding-right:12px;vertical-align:top}@media only screen and (max-width: 480px){.crosstalk-input-checkboxgroup .crosstalk-options-group .crosstalk-options-column{display:block;padding-right:inherit}}.crosstalk-input{margin-bottom:15px}.crosstalk-input .control-label{margin-bottom:0;vertical-align:middle}.crosstalk-input input[type="checkbox"]{margin:4px 0 0;margin-top:1px;line-height:normal}.crosstalk-input .checkbox{position:relative;display:block;margin-top:10px;margin-bottom:10px}.crosstalk-input .checkbox>label{padding-left:20px;margin-bottom:0;font-weight:400;cursor:pointer}.crosstalk-input .checkbox input[type="checkbox"],.crosstalk-input .checkbox-inline input[type="checkbox"]{position:absolute;margin-top:2px;margin-left:-20px}.crosstalk-input .checkbox+.checkbox{margin-top:-5px}.crosstalk-input .checkbox-inline{position:relative;display:inline-block;padding-left:20px;margin-bottom:0;font-weight:400;vertical-align:middle;cursor:pointer}.crosstalk-input .checkbox-inline+.checkbox-inline{margin-top:0;margin-left:10px} 2 | -------------------------------------------------------------------------------- /docs/articles/statcanR_example1_files/crosstalk-1.2.0/css/crosstalk.min.css: -------------------------------------------------------------------------------- 1 | .container-fluid.crosstalk-bscols{margin-left:-30px;margin-right:-30px;white-space:normal}body>.container-fluid.crosstalk-bscols{margin-left:auto;margin-right:auto}.crosstalk-input-checkboxgroup .crosstalk-options-group .crosstalk-options-column{display:inline-block;padding-right:12px;vertical-align:top}@media only screen and (max-width: 480px){.crosstalk-input-checkboxgroup .crosstalk-options-group .crosstalk-options-column{display:block;padding-right:inherit}}.crosstalk-input{margin-bottom:15px}.crosstalk-input .control-label{margin-bottom:0;vertical-align:middle}.crosstalk-input input[type="checkbox"]{margin:4px 0 0;margin-top:1px;line-height:normal}.crosstalk-input .checkbox{position:relative;display:block;margin-top:10px;margin-bottom:10px}.crosstalk-input .checkbox>label{padding-left:20px;margin-bottom:0;font-weight:400;cursor:pointer}.crosstalk-input .checkbox input[type="checkbox"],.crosstalk-input .checkbox-inline input[type="checkbox"]{position:absolute;margin-top:2px;margin-left:-20px}.crosstalk-input .checkbox+.checkbox{margin-top:-5px}.crosstalk-input .checkbox-inline{position:relative;display:inline-block;padding-left:20px;margin-bottom:0;font-weight:400;vertical-align:middle;cursor:pointer}.crosstalk-input .checkbox-inline+.checkbox-inline{margin-top:0;margin-left:10px} 2 | -------------------------------------------------------------------------------- /docs/articles/statcanR_example2_files/crosstalk-1.2.0/css/crosstalk.min.css: -------------------------------------------------------------------------------- 1 | .container-fluid.crosstalk-bscols{margin-left:-30px;margin-right:-30px;white-space:normal}body>.container-fluid.crosstalk-bscols{margin-left:auto;margin-right:auto}.crosstalk-input-checkboxgroup .crosstalk-options-group .crosstalk-options-column{display:inline-block;padding-right:12px;vertical-align:top}@media only screen and (max-width: 480px){.crosstalk-input-checkboxgroup .crosstalk-options-group .crosstalk-options-column{display:block;padding-right:inherit}}.crosstalk-input{margin-bottom:15px}.crosstalk-input .control-label{margin-bottom:0;vertical-align:middle}.crosstalk-input input[type="checkbox"]{margin:4px 0 0;margin-top:1px;line-height:normal}.crosstalk-input .checkbox{position:relative;display:block;margin-top:10px;margin-bottom:10px}.crosstalk-input .checkbox>label{padding-left:20px;margin-bottom:0;font-weight:400;cursor:pointer}.crosstalk-input .checkbox input[type="checkbox"],.crosstalk-input .checkbox-inline input[type="checkbox"]{position:absolute;margin-top:2px;margin-left:-20px}.crosstalk-input .checkbox+.checkbox{margin-top:-5px}.crosstalk-input .checkbox-inline{position:relative;display:inline-block;padding-left:20px;margin-bottom:0;font-weight:400;vertical-align:middle;cursor:pointer}.crosstalk-input .checkbox-inline+.checkbox-inline{margin-top:0;margin-left:10px} 2 | -------------------------------------------------------------------------------- /man/statcan_search.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/statcan_search.R 3 | \name{statcan_search} 4 | \alias{statcan_search} 5 | \title{Searching function for statcanR} 6 | \usage{ 7 | statcan_search(keywords, lang) 8 | } 9 | \arguments{ 10 | \item{keywords}{The words that appear in the title or description of the data table} 11 | 12 | \item{lang}{The language wanted} 13 | } 14 | \value{ 15 | The output will be the title, id, description, and release date of a table 16 | } 17 | \description{ 18 | The \code{statcan_search()} function has 2 arguments to fulfill to find a database: {keywords} and {lang}. 19 | The keywords argument refers to words that can be found in either the title or the description of the database. For example, inserting the keywords 20 | "economy","export",and "link" will bring up the title, table id, description, and release date for databases that include these keywords. In this case, only one data table ("Supply and use tables, link-1997 level") 21 | would be returned as it is the only data table containing all three words. 22 | } 23 | \details{ 24 | Easily connect to Statistics Canada's Web Data Service with R. Open economic data (formerly known as CANSIM tables, now identified by Product IDs (PID)) are accessible as a data frame, directly in the user's R environment. 25 | } 26 | \examples{ 27 | statcan_search(c("economy","export","link"),"eng") 28 | } 29 | -------------------------------------------------------------------------------- /man/statcan_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/statCanR.R 3 | \name{statcan_data} 4 | \alias{statcan_data} 5 | \title{statcanR} 6 | \usage{ 7 | statcan_data(tableNumber, lang) 8 | } 9 | \arguments{ 10 | \item{tableNumber}{The table number of the Statistics Canada data table} 11 | 12 | \item{lang}{The language wanted} 13 | } 14 | \value{ 15 | The output will be a data table representing the data associated with the chosen table number. 16 | } 17 | \description{ 18 | Easily connect to Statistics Canada's Web Data Service with R. Open economic data (formerly known as CANSIM tables, now identified by Product IDs (PID)) are accessible as a data frame, directly in the user's R environment. 19 | } 20 | \details{ 21 | The 22 | \code{statcan_data()} function has 2 arguments to fulfill to get data: {tableNumber} & {lang}. 23 | 24 | 25 | The tableNumber argument simply refers to the table number of the Statistics Canada data table a user wants to collect, 26 | such as '27-10-0014-01' for the Federal expenditures on science and technology, by socio-economic objectives, as an example. 27 | 28 | 29 | To get the table number: \url{https://www150.statcan.gc.ca/n1/en/type/data}. 30 | 31 | The second argument, lang, refers to the language. As Canada is a bilingual country, Statistics Canada displays all the economic data in both languages. 32 | Therefore, users can choose to collect satistics data tables in French or English by setting the lang argument with c('fra', 'eng'). 33 | } 34 | \examples{ 35 | #mydata <- statcan_data('27-10-0014-01', 'eng') 36 | 37 | } 38 | -------------------------------------------------------------------------------- /docs/reference/libs/datatables-css-0.0.0/datatables-crosstalk.css: -------------------------------------------------------------------------------- 1 | .dt-crosstalk-fade { 2 | opacity: 0.2; 3 | } 4 | 5 | html body div.DTS div.dataTables_scrollBody { 6 | background: none; 7 | } 8 | 9 | 10 | /* 11 | Fix https://github.com/rstudio/DT/issues/563 12 | If the `table.display` is set to "block" (e.g., pkgdown), the browser will display 13 | datatable objects strangely. The search panel and the page buttons will still be 14 | in full-width but the table body will be "compact" and shorter. 15 | In therory, having this attributes will affect `dom="t"` 16 | with `display: block` users. But in reality, there should be no one. 17 | We may remove the below lines in the future if the upstream agree to have this there. 18 | See https://github.com/DataTables/DataTablesSrc/issues/160 19 | */ 20 | 21 | table.dataTable { 22 | display: table; 23 | } 24 | 25 | 26 | /* 27 | When DTOutput(fill = TRUE), it receives a .html-fill-item class (via htmltools::bindFillRole()), which effectively amounts to `flex: 1 1 auto`. That's mostly fine, but the case where `fillContainer=TRUE`+`height:auto`+`flex-basis:auto` and the container (e.g., a bslib::card()) doesn't have a defined height is a bit problematic since the table wants to fit the parent but the parent wants to fit the table, which results pretty small table height (maybe because there is a minimum height somewhere?). It seems better in this case to impose a 400px height default for the table, which we can do by setting `flex-basis` to 400px (the table is still allowed to grow/shrink when the container has an opinionated height). 28 | */ 29 | 30 | .html-fill-container > .html-fill-item.datatables { 31 | flex-basis: 400px; 32 | } 33 | -------------------------------------------------------------------------------- /docs/articles/statcanR_example1_files/datatables-css-0.0.0/datatables-crosstalk.css: -------------------------------------------------------------------------------- 1 | .dt-crosstalk-fade { 2 | opacity: 0.2; 3 | } 4 | 5 | html body div.DTS div.dataTables_scrollBody { 6 | background: none; 7 | } 8 | 9 | 10 | /* 11 | Fix https://github.com/rstudio/DT/issues/563 12 | If the `table.display` is set to "block" (e.g., pkgdown), the browser will display 13 | datatable objects strangely. The search panel and the page buttons will still be 14 | in full-width but the table body will be "compact" and shorter. 15 | In therory, having this attributes will affect `dom="t"` 16 | with `display: block` users. But in reality, there should be no one. 17 | We may remove the below lines in the future if the upstream agree to have this there. 18 | See https://github.com/DataTables/DataTablesSrc/issues/160 19 | */ 20 | 21 | table.dataTable { 22 | display: table; 23 | } 24 | 25 | 26 | /* 27 | When DTOutput(fill = TRUE), it receives a .html-fill-item class (via htmltools::bindFillRole()), which effectively amounts to `flex: 1 1 auto`. That's mostly fine, but the case where `fillContainer=TRUE`+`height:auto`+`flex-basis:auto` and the container (e.g., a bslib::card()) doesn't have a defined height is a bit problematic since the table wants to fit the parent but the parent wants to fit the table, which results pretty small table height (maybe because there is a minimum height somewhere?). It seems better in this case to impose a 400px height default for the table, which we can do by setting `flex-basis` to 400px (the table is still allowed to grow/shrink when the container has an opinionated height). 28 | */ 29 | 30 | .html-fill-container > .html-fill-item.datatables { 31 | flex-basis: 400px; 32 | } 33 | -------------------------------------------------------------------------------- /docs/articles/statcanR_example2_files/datatables-css-0.0.0/datatables-crosstalk.css: -------------------------------------------------------------------------------- 1 | .dt-crosstalk-fade { 2 | opacity: 0.2; 3 | } 4 | 5 | html body div.DTS div.dataTables_scrollBody { 6 | background: none; 7 | } 8 | 9 | 10 | /* 11 | Fix https://github.com/rstudio/DT/issues/563 12 | If the `table.display` is set to "block" (e.g., pkgdown), the browser will display 13 | datatable objects strangely. The search panel and the page buttons will still be 14 | in full-width but the table body will be "compact" and shorter. 15 | In therory, having this attributes will affect `dom="t"` 16 | with `display: block` users. But in reality, there should be no one. 17 | We may remove the below lines in the future if the upstream agree to have this there. 18 | See https://github.com/DataTables/DataTablesSrc/issues/160 19 | */ 20 | 21 | table.dataTable { 22 | display: table; 23 | } 24 | 25 | 26 | /* 27 | When DTOutput(fill = TRUE), it receives a .html-fill-item class (via htmltools::bindFillRole()), which effectively amounts to `flex: 1 1 auto`. That's mostly fine, but the case where `fillContainer=TRUE`+`height:auto`+`flex-basis:auto` and the container (e.g., a bslib::card()) doesn't have a defined height is a bit problematic since the table wants to fit the parent but the parent wants to fit the table, which results pretty small table height (maybe because there is a minimum height somewhere?). It seems better in this case to impose a 400px height default for the table, which we can do by setting `flex-basis` to 400px (the table is still allowed to grow/shrink when the container has an opinionated height). 28 | */ 29 | 30 | .html-fill-container > .html-fill-item.datatables { 31 | flex-basis: 400px; 32 | } 33 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | 6 | /* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ 7 | 8 | /* All levels of nav */ 9 | nav[data-toggle='toc'] .nav > li > a { 10 | display: block; 11 | padding: 4px 20px; 12 | font-size: 13px; 13 | font-weight: 500; 14 | color: #767676; 15 | } 16 | nav[data-toggle='toc'] .nav > li > a:hover, 17 | nav[data-toggle='toc'] .nav > li > a:focus { 18 | padding-left: 19px; 19 | color: #563d7c; 20 | text-decoration: none; 21 | background-color: transparent; 22 | border-left: 1px solid #563d7c; 23 | } 24 | nav[data-toggle='toc'] .nav > .active > a, 25 | nav[data-toggle='toc'] .nav > .active:hover > a, 26 | nav[data-toggle='toc'] .nav > .active:focus > a { 27 | padding-left: 18px; 28 | font-weight: bold; 29 | color: #563d7c; 30 | background-color: transparent; 31 | border-left: 2px solid #563d7c; 32 | } 33 | 34 | /* Nav: second level (shown on .active) */ 35 | nav[data-toggle='toc'] .nav .nav { 36 | display: none; /* Hide by default, but at >768px, show it */ 37 | padding-bottom: 10px; 38 | } 39 | nav[data-toggle='toc'] .nav .nav > li > a { 40 | padding-top: 1px; 41 | padding-bottom: 1px; 42 | padding-left: 30px; 43 | font-size: 12px; 44 | font-weight: normal; 45 | } 46 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 47 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 48 | padding-left: 29px; 49 | } 50 | nav[data-toggle='toc'] .nav .nav > .active > a, 51 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 52 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 53 | padding-left: 28px; 54 | font-weight: 500; 55 | } 56 | 57 | /* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ 58 | nav[data-toggle='toc'] .nav > .active > ul { 59 | display: block; 60 | } 61 | -------------------------------------------------------------------------------- /docs/reference/libs/crosstalk-1.2.0/scss/crosstalk.scss: -------------------------------------------------------------------------------- 1 | /* Adjust margins outwards, so column contents line up with the edges of the 2 | parent of container-fluid. */ 3 | .container-fluid.crosstalk-bscols { 4 | margin-left: -30px; 5 | margin-right: -30px; 6 | white-space: normal; 7 | } 8 | 9 | /* But don't adjust the margins outwards if we're directly under the body, 10 | i.e. we were the top-level of something at the console. */ 11 | body > .container-fluid.crosstalk-bscols { 12 | margin-left: auto; 13 | margin-right: auto; 14 | } 15 | 16 | .crosstalk-input-checkboxgroup .crosstalk-options-group .crosstalk-options-column { 17 | display: inline-block; 18 | padding-right: 12px; 19 | vertical-align: top; 20 | } 21 | 22 | @media only screen and (max-width:480px) { 23 | .crosstalk-input-checkboxgroup .crosstalk-options-group .crosstalk-options-column { 24 | display: block; 25 | padding-right: inherit; 26 | } 27 | } 28 | 29 | /* Relevant BS3 styles to make filter_checkbox() look reasonable without Bootstrap */ 30 | .crosstalk-input { 31 | margin-bottom: 15px; /* a la .form-group */ 32 | .control-label { 33 | margin-bottom: 0; 34 | vertical-align: middle; 35 | } 36 | input[type="checkbox"] { 37 | margin: 4px 0 0; 38 | margin-top: 1px; 39 | line-height: normal; 40 | } 41 | .checkbox { 42 | position: relative; 43 | display: block; 44 | margin-top: 10px; 45 | margin-bottom: 10px; 46 | } 47 | .checkbox > label{ 48 | padding-left: 20px; 49 | margin-bottom: 0; 50 | font-weight: 400; 51 | cursor: pointer; 52 | } 53 | .checkbox input[type="checkbox"], 54 | .checkbox-inline input[type="checkbox"] { 55 | position: absolute; 56 | margin-top: 2px; 57 | margin-left: -20px; 58 | } 59 | .checkbox + .checkbox { 60 | margin-top: -5px; 61 | } 62 | .checkbox-inline { 63 | position: relative; 64 | display: inline-block; 65 | padding-left: 20px; 66 | margin-bottom: 0; 67 | font-weight: 400; 68 | vertical-align: middle; 69 | cursor: pointer; 70 | } 71 | .checkbox-inline + .checkbox-inline { 72 | margin-top: 0; 73 | margin-left: 10px; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /docs/articles/statcanR_example1_files/crosstalk-1.2.0/scss/crosstalk.scss: -------------------------------------------------------------------------------- 1 | /* Adjust margins outwards, so column contents line up with the edges of the 2 | parent of container-fluid. */ 3 | .container-fluid.crosstalk-bscols { 4 | margin-left: -30px; 5 | margin-right: -30px; 6 | white-space: normal; 7 | } 8 | 9 | /* But don't adjust the margins outwards if we're directly under the body, 10 | i.e. we were the top-level of something at the console. */ 11 | body > .container-fluid.crosstalk-bscols { 12 | margin-left: auto; 13 | margin-right: auto; 14 | } 15 | 16 | .crosstalk-input-checkboxgroup .crosstalk-options-group .crosstalk-options-column { 17 | display: inline-block; 18 | padding-right: 12px; 19 | vertical-align: top; 20 | } 21 | 22 | @media only screen and (max-width:480px) { 23 | .crosstalk-input-checkboxgroup .crosstalk-options-group .crosstalk-options-column { 24 | display: block; 25 | padding-right: inherit; 26 | } 27 | } 28 | 29 | /* Relevant BS3 styles to make filter_checkbox() look reasonable without Bootstrap */ 30 | .crosstalk-input { 31 | margin-bottom: 15px; /* a la .form-group */ 32 | .control-label { 33 | margin-bottom: 0; 34 | vertical-align: middle; 35 | } 36 | input[type="checkbox"] { 37 | margin: 4px 0 0; 38 | margin-top: 1px; 39 | line-height: normal; 40 | } 41 | .checkbox { 42 | position: relative; 43 | display: block; 44 | margin-top: 10px; 45 | margin-bottom: 10px; 46 | } 47 | .checkbox > label{ 48 | padding-left: 20px; 49 | margin-bottom: 0; 50 | font-weight: 400; 51 | cursor: pointer; 52 | } 53 | .checkbox input[type="checkbox"], 54 | .checkbox-inline input[type="checkbox"] { 55 | position: absolute; 56 | margin-top: 2px; 57 | margin-left: -20px; 58 | } 59 | .checkbox + .checkbox { 60 | margin-top: -5px; 61 | } 62 | .checkbox-inline { 63 | position: relative; 64 | display: inline-block; 65 | padding-left: 20px; 66 | margin-bottom: 0; 67 | font-weight: 400; 68 | vertical-align: middle; 69 | cursor: pointer; 70 | } 71 | .checkbox-inline + .checkbox-inline { 72 | margin-top: 0; 73 | margin-left: 10px; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /docs/articles/statcanR_example2_files/crosstalk-1.2.0/scss/crosstalk.scss: -------------------------------------------------------------------------------- 1 | /* Adjust margins outwards, so column contents line up with the edges of the 2 | parent of container-fluid. */ 3 | .container-fluid.crosstalk-bscols { 4 | margin-left: -30px; 5 | margin-right: -30px; 6 | white-space: normal; 7 | } 8 | 9 | /* But don't adjust the margins outwards if we're directly under the body, 10 | i.e. we were the top-level of something at the console. */ 11 | body > .container-fluid.crosstalk-bscols { 12 | margin-left: auto; 13 | margin-right: auto; 14 | } 15 | 16 | .crosstalk-input-checkboxgroup .crosstalk-options-group .crosstalk-options-column { 17 | display: inline-block; 18 | padding-right: 12px; 19 | vertical-align: top; 20 | } 21 | 22 | @media only screen and (max-width:480px) { 23 | .crosstalk-input-checkboxgroup .crosstalk-options-group .crosstalk-options-column { 24 | display: block; 25 | padding-right: inherit; 26 | } 27 | } 28 | 29 | /* Relevant BS3 styles to make filter_checkbox() look reasonable without Bootstrap */ 30 | .crosstalk-input { 31 | margin-bottom: 15px; /* a la .form-group */ 32 | .control-label { 33 | margin-bottom: 0; 34 | vertical-align: middle; 35 | } 36 | input[type="checkbox"] { 37 | margin: 4px 0 0; 38 | margin-top: 1px; 39 | line-height: normal; 40 | } 41 | .checkbox { 42 | position: relative; 43 | display: block; 44 | margin-top: 10px; 45 | margin-bottom: 10px; 46 | } 47 | .checkbox > label{ 48 | padding-left: 20px; 49 | margin-bottom: 0; 50 | font-weight: 400; 51 | cursor: pointer; 52 | } 53 | .checkbox input[type="checkbox"], 54 | .checkbox-inline input[type="checkbox"] { 55 | position: absolute; 56 | margin-top: 2px; 57 | margin-left: -20px; 58 | } 59 | .checkbox + .checkbox { 60 | margin-top: -5px; 61 | } 62 | .checkbox-inline { 63 | position: relative; 64 | display: inline-block; 65 | padding-left: 20px; 66 | margin-bottom: 0; 67 | font-weight: 400; 68 | vertical-align: middle; 69 | cursor: pointer; 70 | } 71 | .checkbox-inline + .checkbox-inline { 72 | margin-top: 0; 73 | margin-left: 10px; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /docs/docsearch.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | 3 | // register a handler to move the focus to the search bar 4 | // upon pressing shift + "/" (i.e. "?") 5 | $(document).on('keydown', function(e) { 6 | if (e.shiftKey && e.keyCode == 191) { 7 | e.preventDefault(); 8 | $("#search-input").focus(); 9 | } 10 | }); 11 | 12 | $(document).ready(function() { 13 | // do keyword highlighting 14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ 15 | var mark = function() { 16 | 17 | var referrer = document.URL ; 18 | var paramKey = "q" ; 19 | 20 | if (referrer.indexOf("?") !== -1) { 21 | var qs = referrer.substr(referrer.indexOf('?') + 1); 22 | var qs_noanchor = qs.split('#')[0]; 23 | var qsa = qs_noanchor.split('&'); 24 | var keyword = ""; 25 | 26 | for (var i = 0; i < qsa.length; i++) { 27 | var currentParam = qsa[i].split('='); 28 | 29 | if (currentParam.length !== 2) { 30 | continue; 31 | } 32 | 33 | if (currentParam[0] == paramKey) { 34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); 35 | } 36 | } 37 | 38 | if (keyword !== "") { 39 | $(".contents").unmark({ 40 | done: function() { 41 | $(".contents").mark(keyword); 42 | } 43 | }); 44 | } 45 | } 46 | }; 47 | 48 | mark(); 49 | }); 50 | }); 51 | 52 | /* Search term highlighting ------------------------------*/ 53 | 54 | function matchedWords(hit) { 55 | var words = []; 56 | 57 | var hierarchy = hit._highlightResult.hierarchy; 58 | // loop to fetch from lvl0, lvl1, etc. 59 | for (var idx in hierarchy) { 60 | words = words.concat(hierarchy[idx].matchedWords); 61 | } 62 | 63 | var content = hit._highlightResult.content; 64 | if (content) { 65 | words = words.concat(content.matchedWords); 66 | } 67 | 68 | // return unique words 69 | var words_uniq = [...new Set(words)]; 70 | return words_uniq; 71 | } 72 | 73 | function updateHitURL(hit) { 74 | 75 | var words = matchedWords(hit); 76 | var url = ""; 77 | 78 | if (hit.anchor) { 79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; 80 | } else { 81 | url = hit.url + '?q=' + escape(words.join(" ")); 82 | } 83 | 84 | return url; 85 | } 86 | -------------------------------------------------------------------------------- /R/statcan_search.R: -------------------------------------------------------------------------------- 1 | #' Searching function for statcanR 2 | #' 3 | #' 4 | #' Easily connect to Statistics Canada's Web Data Service with R. Open economic data (formerly known as CANSIM tables, now identified by Product IDs (PID)) are accessible as a data frame, directly in the user's R environment. 5 | #' 6 | #' 7 | #' @description The \code{statcan_search()} function has 2 arguments to fulfill to find a database: {keywords} and {lang}. 8 | #' The keywords argument refers to words that can be found in either the title or the description of the database. For example, inserting the keywords 9 | #' "economy","export",and "link" will bring up the title, table id, description, and release date for databases that include these keywords. In this case, only one data table ("Supply and use tables, link-1997 level") 10 | #' would be returned as it is the only data table containing all three words. 11 | #' 12 | #' 13 | #' @param keywords The words that appear in the title or description of the data table 14 | #' @param lang The language wanted 15 | #' 16 | #' @return The output will be the title, id, description, and release date of a table 17 | #' @export 18 | #' 19 | #' 20 | #' @import DT 21 | #' @import curl 22 | #' @import qpdf 23 | #' @import qs 24 | #' @import dplyr 25 | #' @import ggplot2 26 | #' @import reshape2 27 | 28 | #' @examples statcan_search(c("economy","export","link"),"eng") 29 | 30 | 31 | statcan_search <- function(keywords,lang) { 32 | 33 | # Get the whole list of available tables from statCan into a temp forlder 34 | url <- paste0("https://warin.ca/datalake/statcanR/statcan_data.qs") 35 | 36 | if (httr::http_error(url)) 37 | { # network is down = message (not an error anymore) 38 | message("No tables with this combination of keywords") 39 | } else{ 40 | path <- file.path(tempdir(), "temp.qs") 41 | curl::curl_download(url, path) 42 | qs_file <- file.path(paste0(tempdir(), "/temp.qs")) 43 | statcandata <- qs::qread(qs_file) 44 | 45 | } 46 | 47 | # Loading data 48 | if (lang == "eng") { 49 | 50 | # Creating the keyword matches 51 | keyword_regex <- paste0("(", paste(keywords, collapse = "|"), ")", collapse = ".*") 52 | 53 | matches <- apply(statcandata, 1, function(row) { 54 | all(sapply(keywords, function(x) { 55 | grepl(x, paste(as.character(row), collapse = " ")) 56 | })) 57 | }) 58 | 59 | # Keep only obs with matched keywords and create datatable 60 | filtered_data <- statcandata[matches, ] 61 | return(datatable(filtered_data,options = list(pageLength = 5))) 62 | } 63 | 64 | if (lang == "fra") { 65 | 66 | # Creating the keyword matches 67 | keyword_regex <- paste0("(", paste(keywords, collapse = "|"), ")", collapse = ".*") 68 | 69 | matches <- apply(statcandata, 1, function(row) { 70 | all(sapply(keywords, function(x) { 71 | grepl(x, paste(as.character(row), collapse = " ")) 72 | })) 73 | }) 74 | 75 | 76 | # Keep only obs with matched keywords and create datatable 77 | filtered_data <- statcandata[matches, ] 78 | return(datatable(filtered_data,options = list(pageLength = 5))) 79 | } 80 | } 81 | 82 | -------------------------------------------------------------------------------- /docs/pkgdown.js: -------------------------------------------------------------------------------- 1 | /* http://gregfranko.com/blog/jquery-best-practices/ */ 2 | (function($) { 3 | $(function() { 4 | 5 | $('.navbar-fixed-top').headroom(); 6 | 7 | $('body').css('padding-top', $('.navbar').height() + 10); 8 | $(window).resize(function(){ 9 | $('body').css('padding-top', $('.navbar').height() + 10); 10 | }); 11 | 12 | $('[data-toggle="tooltip"]').tooltip(); 13 | 14 | var cur_path = paths(location.pathname); 15 | var links = $("#navbar ul li a"); 16 | var max_length = -1; 17 | var pos = -1; 18 | for (var i = 0; i < links.length; i++) { 19 | if (links[i].getAttribute("href") === "#") 20 | continue; 21 | // Ignore external links 22 | if (links[i].host !== location.host) 23 | continue; 24 | 25 | var nav_path = paths(links[i].pathname); 26 | 27 | var length = prefix_length(nav_path, cur_path); 28 | if (length > max_length) { 29 | max_length = length; 30 | pos = i; 31 | } 32 | } 33 | 34 | // Add class to parent
  • , and enclosing
  • if in dropdown 35 | if (pos >= 0) { 36 | var menu_anchor = $(links[pos]); 37 | menu_anchor.parent().addClass("active"); 38 | menu_anchor.closest("li.dropdown").addClass("active"); 39 | } 40 | }); 41 | 42 | function paths(pathname) { 43 | var pieces = pathname.split("/"); 44 | pieces.shift(); // always starts with / 45 | 46 | var end = pieces[pieces.length - 1]; 47 | if (end === "index.html" || end === "") 48 | pieces.pop(); 49 | return(pieces); 50 | } 51 | 52 | // Returns -1 if not found 53 | function prefix_length(needle, haystack) { 54 | if (needle.length > haystack.length) 55 | return(-1); 56 | 57 | // Special case for length-0 haystack, since for loop won't run 58 | if (haystack.length === 0) { 59 | return(needle.length === 0 ? 0 : -1); 60 | } 61 | 62 | for (var i = 0; i < haystack.length; i++) { 63 | if (needle[i] != haystack[i]) 64 | return(i); 65 | } 66 | 67 | return(haystack.length); 68 | } 69 | 70 | /* Clipboard --------------------------*/ 71 | 72 | function changeTooltipMessage(element, msg) { 73 | var tooltipOriginalTitle=element.getAttribute('data-original-title'); 74 | element.setAttribute('data-original-title', msg); 75 | $(element).tooltip('show'); 76 | element.setAttribute('data-original-title', tooltipOriginalTitle); 77 | } 78 | 79 | if(ClipboardJS.isSupported()) { 80 | $(document).ready(function() { 81 | var copyButton = ""; 82 | 83 | $("div.sourceCode").addClass("hasCopyButton"); 84 | 85 | // Insert copy buttons: 86 | $(copyButton).prependTo(".hasCopyButton"); 87 | 88 | // Initialize tooltips: 89 | $('.btn-copy-ex').tooltip({container: 'body'}); 90 | 91 | // Initialize clipboard: 92 | var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { 93 | text: function(trigger) { 94 | return trigger.parentNode.textContent.replace(/\n#>[^\n]*/g, ""); 95 | } 96 | }); 97 | 98 | clipboardBtnCopies.on('success', function(e) { 99 | changeTooltipMessage(e.trigger, 'Copied!'); 100 | e.clearSelection(); 101 | }); 102 | 103 | clipboardBtnCopies.on('error', function() { 104 | changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); 105 | }); 106 | }); 107 | } 108 | })(window.jQuery || window.$) 109 | -------------------------------------------------------------------------------- /docs/LICENSE-text.html: -------------------------------------------------------------------------------- 1 | 2 | License • statcanR 6 | 7 | 8 |
    9 |
    53 | 54 | 55 | 56 |
    57 |
    58 | 61 | 62 |
    YEAR: 2020
    63 | COPYRIGHT HOLDER: Thierry Warin ; Romain Le Duc
    64 | 
    65 | 66 |
    67 | 68 | 71 | 72 |
    73 | 74 | 75 | 76 |
    79 | 80 |
    81 |

    Site built with pkgdown 2.0.7.

    82 |
    83 | 84 |
    85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /docs/articles/index.html: -------------------------------------------------------------------------------- 1 | 2 | Articles • statcanR 6 | 7 | 8 |
    9 |
    53 | 54 | 55 | 56 |
    57 |
    58 | 61 | 62 |
    63 |

    All vignettes

    64 |

    65 | 66 |
    statCanR
    67 |
    68 |
    vignettes
    69 |
    70 |
    71 |
    72 |
    73 | 74 | 75 |
    78 | 79 |
    80 |

    Site built with pkgdown 2.0.7.

    81 |
    82 | 83 |
    84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | (function() { 6 | 'use strict'; 7 | 8 | window.Toc = { 9 | helpers: { 10 | // return all matching elements in the set, or their descendants 11 | findOrFilter: function($el, selector) { 12 | // http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/ 13 | // http://stackoverflow.com/a/12731439/358804 14 | var $descendants = $el.find(selector); 15 | return $el.filter(selector).add($descendants).filter(':not([data-toc-skip])'); 16 | }, 17 | 18 | generateUniqueIdBase: function(el) { 19 | var text = $(el).text(); 20 | var anchor = text.trim().toLowerCase().replace(/[^A-Za-z0-9]+/g, '-'); 21 | return anchor || el.tagName.toLowerCase(); 22 | }, 23 | 24 | generateUniqueId: function(el) { 25 | var anchorBase = this.generateUniqueIdBase(el); 26 | for (var i = 0; ; i++) { 27 | var anchor = anchorBase; 28 | if (i > 0) { 29 | // add suffix 30 | anchor += '-' + i; 31 | } 32 | // check if ID already exists 33 | if (!document.getElementById(anchor)) { 34 | return anchor; 35 | } 36 | } 37 | }, 38 | 39 | generateAnchor: function(el) { 40 | if (el.id) { 41 | return el.id; 42 | } else { 43 | var anchor = this.generateUniqueId(el); 44 | el.id = anchor; 45 | return anchor; 46 | } 47 | }, 48 | 49 | createNavList: function() { 50 | return $(''); 51 | }, 52 | 53 | createChildNavList: function($parent) { 54 | var $childList = this.createNavList(); 55 | $parent.append($childList); 56 | return $childList; 57 | }, 58 | 59 | generateNavEl: function(anchor, text) { 60 | var $a = $(''); 61 | $a.attr('href', '#' + anchor); 62 | $a.text(text); 63 | var $li = $('
  • '); 64 | $li.append($a); 65 | return $li; 66 | }, 67 | 68 | generateNavItem: function(headingEl) { 69 | var anchor = this.generateAnchor(headingEl); 70 | var $heading = $(headingEl); 71 | var text = $heading.data('toc-text') || $heading.text(); 72 | return this.generateNavEl(anchor, text); 73 | }, 74 | 75 | // Find the first heading level (`

    `, then `

    `, etc.) that has more than one element. Defaults to 1 (for `

    `). 76 | getTopLevel: function($scope) { 77 | for (var i = 1; i <= 6; i++) { 78 | var $headings = this.findOrFilter($scope, 'h' + i); 79 | if ($headings.length > 1) { 80 | return i; 81 | } 82 | } 83 | 84 | return 1; 85 | }, 86 | 87 | // returns the elements for the top level, and the next below it 88 | getHeadings: function($scope, topLevel) { 89 | var topSelector = 'h' + topLevel; 90 | 91 | var secondaryLevel = topLevel + 1; 92 | var secondarySelector = 'h' + secondaryLevel; 93 | 94 | return this.findOrFilter($scope, topSelector + ',' + secondarySelector); 95 | }, 96 | 97 | getNavLevel: function(el) { 98 | return parseInt(el.tagName.charAt(1), 10); 99 | }, 100 | 101 | populateNav: function($topContext, topLevel, $headings) { 102 | var $context = $topContext; 103 | var $prevNav; 104 | 105 | var helpers = this; 106 | $headings.each(function(i, el) { 107 | var $newNav = helpers.generateNavItem(el); 108 | var navLevel = helpers.getNavLevel(el); 109 | 110 | // determine the proper $context 111 | if (navLevel === topLevel) { 112 | // use top level 113 | $context = $topContext; 114 | } else if ($prevNav && $context === $topContext) { 115 | // create a new level of the tree and switch to it 116 | $context = helpers.createChildNavList($prevNav); 117 | } // else use the current $context 118 | 119 | $context.append($newNav); 120 | 121 | $prevNav = $newNav; 122 | }); 123 | }, 124 | 125 | parseOps: function(arg) { 126 | var opts; 127 | if (arg.jquery) { 128 | opts = { 129 | $nav: arg 130 | }; 131 | } else { 132 | opts = arg; 133 | } 134 | opts.$scope = opts.$scope || $(document.body); 135 | return opts; 136 | } 137 | }, 138 | 139 | // accepts a jQuery object, or an options object 140 | init: function(opts) { 141 | opts = this.helpers.parseOps(opts); 142 | 143 | // ensure that the data attribute is in place for styling 144 | opts.$nav.attr('data-toggle', 'toc'); 145 | 146 | var $topContext = this.helpers.createChildNavList(opts.$nav); 147 | var topLevel = this.helpers.getTopLevel(opts.$scope); 148 | var $headings = this.helpers.getHeadings(opts.$scope, topLevel); 149 | this.helpers.populateNav($topContext, topLevel, $headings); 150 | } 151 | }; 152 | 153 | $(function() { 154 | $('nav[data-toggle="toc"]').each(function(i, el) { 155 | var $nav = $(el); 156 | Toc.init($nav); 157 | }); 158 | }); 159 | })(); 160 | -------------------------------------------------------------------------------- /docs/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Page not found (404) • statcanR 9 | 10 | 11 | 12 | 13 | 14 | 15 | 19 | 20 | 21 | 22 | 23 |
    24 |
    76 | 77 | 78 | 79 | 80 |
    81 |
    82 | 85 | 86 | Content not found. Please use links in the navbar. 87 | 88 |
    89 | 90 | 94 | 95 |
    96 | 97 | 98 | 99 |
    103 | 104 |
    105 |

    106 |

    Site built with pkgdown 2.0.7.

    107 |
    108 | 109 |
    110 |
    111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /inst/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # statcanR 5 | 6 | 7 | 8 | [![Travis build 9 | status](https://travis-ci.com/warint/statcanR.svg?branch=master)](https://app.travis-ci.com/github/warint/statcanR) 10 | [![AppVeyor build 11 | status](https://ci.appveyor.com/api/projects/status/github/warint/statcanR?branch=master&svg=true)](https://ci.appveyor.com/project/warint/statcanR) 12 | [![Mentioned in 13 | Awesome](https://awesome.re/mentioned-badge.svg)](https://github.com/SNStatComp/awesome-official-statistics-software) 14 | [![CRAN 15 | status](https://www.r-pkg.org/badges/version/statcanR)](https://CRAN.R-project.org/package=statcanR) 16 | [![](https://cranlogs.r-pkg.org/badges/grand-total/statcanR?color=blue)](https://cran.r-project.org/package=statcanR) 17 | 18 | 19 | 20 | # Overview 21 | 22 | Easily connect to Statistics Canada’s Web Data Service with R. Open 23 | economic data (formerly known as CANSIM tables, now identified by 24 | Product IDs (PID)) are accessible as a data frame, directly in the 25 | user’s R environment. 26 | 27 | ## Shiny App : statcanR ExploR 28 | 29 | 30 | 31 | For people less comfortable with R and to allow more people to have 32 | access to our package, we have also developed a Shiny 33 | application.Through the same logic present in our package, researchers 34 | can retrieve data from Statistics Canada. 35 | 36 | statcanR EploR is available [\[here\]](https://warin.ca/shiny/statcanr/) 37 | 38 | ## Installation 39 | 40 | The released version of statcanR package is accessible through CRAN and 41 | devtools. 42 | 43 | ``` r 44 | install.packages("statcanR") 45 | 46 | install.packages("devtools") 47 | devtools::install_github('warint/statcanR') 48 | ``` 49 | 50 | ## Example 51 | 52 | This section presents an example of how to use the `statcanR` R package 53 | and its function `statcan_data()` and `statcan_download_data()`. 54 | 55 | The following example is provided to illustrate how to use the 56 | functions. It consists in collecting some descriptive statistics about 57 | the Canadian Labour Force at the federal, provincial and industrial 58 | levels, on a monthly basis. 59 | 60 | With a simple web search ‘statistics canada wages by industry 61 | metropolitan area monthly’, the table number can easily be found on 62 | Statisitcs Canada’s webpage. Here is below a figure that illustrates 63 | this example, such as ‘27-10-0014-01’ for the Federal expenditures on 64 | science and technology, by socio-economic objectives. 65 | 66 | Once the table number is identified, the statcan_data() function is easy 67 | to use in order to collect the data, as following: 68 | 69 | ``` r 70 | library(statcanR) 71 | mydata <- statcan_data("27-10-0014-01","eng") 72 | ``` 73 | 74 | For the `statcan_download_data()` function there is no difference on how 75 | to use it, the only difference is that this function allow you to 76 | download the data in a csv file on top of having the data in your 77 | environment. 78 | 79 | ``` r 80 | library(statcanR) 81 | mydata <- statcan_download_data("27-10-0014-01","eng") 82 | ``` 83 | 84 | ### Video Tutorial 85 | 86 | Tutorial made by Professor Charles Saunders, Director of Master of 87 | Financial Economics Program at Western University 88 | [biography](https://economics.uwo.ca/people/faculty/saunders.html) 89 | 90 | Thanks! 91 | 92 | 93 | 94 | ### Statistics Canada Open Licence 95 | 96 | This licence is issued on behalf of Her Majesty the Queen in Right of 97 | Canada, as represented by the Minister for Statistics Canada 98 | (“Statistics Canada”) to you (an individual or a legal entity that you 99 | are authorized to represent). 100 | 101 | Statistics Canada may modify this licence at any time, and such 102 | modifications shall be effective immediately upon posting of the 103 | modified licence on the Statistics Canada website. Your use of the 104 | Information will be governed by the terms of the licence in force as of 105 | the date and time you accessed the Information. 106 | 107 | Please refer to the [terms of 108 | licence](https://www.statcan.gc.ca/eng/reference/licence) before using 109 | the Information. 110 | 111 | ##### Acknowledgment of Source according to Statistics Canada Open Licence Agreement 112 | 113 | Statistics Canada has a specific procedure regarding the ackowledgment 114 | of source : 115 | 116 | You shall include and maintain the following notice on all licensed 117 | rights of the Information: 118 | 119 | Source: Statistics Canada, name of product, reference date. Reproduced and distributed on an "as is" basis with the permission of Statistics Canada. 120 | 121 | Where any Information is contained within a Value-added Product, you 122 | shall include on such Value-added Product the following notice: 123 | 124 | Adapted from Statistics Canada, name of product, reference date. This does not constitute an endorsement by Statistics Canada of this product. 125 | 126 | ### Cite statcanR 127 | 128 | To cite stantcanR package in your work: 129 | 130 | Warin, T., Romain Le Duc (2019). statcanR: Client for Statistics 131 | Canada’s Open Economic Data. v0.1.0. 132 | 133 | ``` r 134 | @Manual{R-statcanR, 135 | title = {statcanR: Client for Statistics Canada's Open Economic Data}, 136 | author = {Thierry Warin and Romain {Le Duc}}, 137 | note = {R package version 0.1.0}, 138 | url = {https://github.com/warint/statcanR}, 139 | year = {2019}, 140 | doi = "10.6084/m9.figshare.10544735.v1" 141 | } 142 | ``` 143 | 144 | ### Acknowledgments 145 | 146 | The authors would like to thank the Center for Interuniversity Research 147 | and Analysis of Organizations (CIRANO, Montreal) for its support, as 148 | well as Thibault Senegas, Marine Leroi and Martin Paquette. However, 149 | errors and omissions are ours. 150 | -------------------------------------------------------------------------------- /docs/articles/vignettes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | vignettes • statcanR 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 20 | 21 | 22 | 23 | 24 |
    25 |
    77 | 78 | 79 | 80 | 81 |
    82 |
    83 | 91 | 92 | 93 | 94 | 96 |
    97 | 98 | 101 | 102 |
    103 | 104 | 105 | 106 |
    110 | 111 |
    112 |

    113 |

    Site built with pkgdown 2.0.7.

    114 |
    115 | 116 |
    117 |
    118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /docs/reference/index.html: -------------------------------------------------------------------------------- 1 | 2 | Function reference • statcanR 6 | 7 | 8 |
    9 |
    53 | 54 | 55 | 56 |
    57 |
    58 | 61 | 62 | 66 | 69 | 70 | 73 | 74 | 77 | 78 |
    63 |

    All functions

    64 |

    65 |
    67 |

    statcan_data()

    68 |

    statcanR

    71 |

    statcan_download_data()

    72 |

    statcanR download data function

    75 |

    statcan_search()

    76 |

    Searching function for statcanR

    79 | 80 | 83 |
    84 | 85 | 86 |
    89 | 90 |
    91 |

    Site built with pkgdown 2.0.7.

    92 |
    93 | 94 |
    95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /CITATION.cff: -------------------------------------------------------------------------------- 1 | # ----------------------------------------------------------- 2 | # CITATION file created with {cffr} R package, v0.4.1 3 | # See also: https://docs.ropensci.org/cffr/ 4 | # ----------------------------------------------------------- 5 | 6 | cff-version: 1.2.0 7 | message: 'To cite package "statcanR" in publications use:' 8 | type: software 9 | license: MIT 10 | title: 'Access Statistics Canada’s Open Economic Data for Statistics and Data Science Courses' 11 | version: 0.2.5 12 | abstract: This article is about the two conflicting goals when teaching statistics or data science courses based on real-world data in a business school environment. We propose to look at structured socio-economic data about the Canadian economy. Canada was ranked 8th in 2017 by Open Data Watch (Government of Canada) for its data accessibility policy. Statistics Canada offers several ways to access data across its over 11,000 data tables. We built an R package to ease access to Statistics Canada's open economic data. With this package, we offer students another option to collect data about the Canadian economy. Warin (2024) . 13 | authors: 14 | - family-names: Warin 15 | given-names: Thierry 16 | email: thierry.warin@hec.ca 17 | orcid: https://orcid.org/0000-0002-5921-3428 18 | repository: https://CRAN.R-project.org/package=statcanR 19 | repository-code: https://github.com/warint/statcanR/issues/ 20 | url: https://github.com/warint/statcanR/ 21 | contact: 22 | - family-names: Warin 23 | given-names: Thierry 24 | email: thierry.warin@hec.ca 25 | orcid: https://orcid.org/0000-0002-5921-3428 26 | references: 27 | - type: software 28 | title: knitr 29 | abstract: 'knitr: A General-Purpose Package for Dynamic Report Generation in R' 30 | notes: Suggests 31 | url: https://yihui.org/knitr/ 32 | repository: https://CRAN.R-project.org/package=knitr 33 | authors: 34 | - family-names: Xie 35 | given-names: Yihui 36 | email: xie@yihui.name 37 | orcid: https://orcid.org/0000-0003-0645-5666 38 | year: '2023' 39 | - type: software 40 | title: rmarkdown 41 | abstract: 'rmarkdown: Dynamic Documents for R' 42 | notes: Suggests 43 | url: https://pkgs.rstudio.com/rmarkdown/ 44 | repository: https://CRAN.R-project.org/package=rmarkdown 45 | authors: 46 | - family-names: Allaire 47 | given-names: JJ 48 | email: jj@rstudio.com 49 | - family-names: Xie 50 | given-names: Yihui 51 | email: xie@yihui.name 52 | orcid: https://orcid.org/0000-0003-0645-5666 53 | - family-names: McPherson 54 | given-names: Jonathan 55 | email: jonathan@rstudio.com 56 | - family-names: Luraschi 57 | given-names: Javier 58 | email: javier@rstudio.com 59 | - family-names: Ushey 60 | given-names: Kevin 61 | email: kevin@rstudio.com 62 | - family-names: Atkins 63 | given-names: Aron 64 | email: aron@rstudio.com 65 | - family-names: Wickham 66 | given-names: Hadley 67 | email: hadley@rstudio.com 68 | - family-names: Cheng 69 | given-names: Joe 70 | email: joe@rstudio.com 71 | - family-names: Chang 72 | given-names: Winston 73 | email: winston@rstudio.com 74 | - family-names: Iannone 75 | given-names: Richard 76 | email: rich@rstudio.com 77 | orcid: https://orcid.org/0000-0003-3925-190X 78 | year: '2023' 79 | - type: software 80 | title: data.table 81 | abstract: 'data.table: Extension of `data.frame`' 82 | notes: Imports 83 | url: https://r-datatable.com 84 | repository: https://CRAN.R-project.org/package=data.table 85 | authors: 86 | - family-names: Dowle 87 | given-names: Matt 88 | email: mattjdowle@gmail.com 89 | - family-names: Srinivasan 90 | given-names: Arun 91 | email: asrini@pm.me 92 | year: '2023' 93 | - type: software 94 | title: qpdf 95 | abstract: 'qpdf: Split, Combine and Compress PDF Files' 96 | notes: Imports 97 | url: https://docs.ropensci.org/qpdf/ 98 | repository: https://CRAN.R-project.org/package=qpdf 99 | authors: 100 | - family-names: Ooms 101 | given-names: Jeroen 102 | email: jeroen@berkeley.edu 103 | orcid: https://orcid.org/0000-0002-4035-0289 104 | year: '2023' 105 | - type: software 106 | title: DT 107 | abstract: 'DT: A Wrapper of the JavaScript Library ''DataTables''' 108 | notes: Imports 109 | url: https://github.com/rstudio/DT 110 | repository: https://CRAN.R-project.org/package=DT 111 | authors: 112 | - family-names: Xie 113 | given-names: Yihui 114 | email: xie@yihui.name 115 | - family-names: Cheng 116 | given-names: Joe 117 | - family-names: Tan 118 | given-names: Xianying 119 | year: '2023' 120 | - type: software 121 | title: curl 122 | abstract: 'curl: A Modern and Flexible Web Client for R' 123 | notes: Imports 124 | url: https://curl.se/libcurl/ 125 | repository: https://CRAN.R-project.org/package=curl 126 | authors: 127 | - family-names: Ooms 128 | given-names: Jeroen 129 | email: jeroen@berkeley.edu 130 | orcid: https://orcid.org/0000-0002-4035-0289 131 | year: '2023' 132 | - type: software 133 | title: httr 134 | abstract: 'httr: Tools for Working with URLs and HTTP' 135 | notes: Imports 136 | url: https://httr.r-lib.org/ 137 | repository: https://CRAN.R-project.org/package=httr 138 | authors: 139 | - family-names: Wickham 140 | given-names: Hadley 141 | email: hadley@rstudio.com 142 | year: '2023' 143 | - type: software 144 | title: readr 145 | abstract: 'readr: Read Rectangular Text Data' 146 | notes: Imports 147 | url: https://readr.tidyverse.org 148 | repository: https://CRAN.R-project.org/package=readr 149 | authors: 150 | - family-names: Wickham 151 | given-names: Hadley 152 | email: hadley@rstudio.com 153 | - family-names: Hester 154 | given-names: Jim 155 | - family-names: Bryan 156 | given-names: Jennifer 157 | email: jenny@rstudio.com 158 | orcid: https://orcid.org/0000-0002-6983-2759 159 | year: '2023' 160 | - type: software 161 | title: tibble 162 | abstract: 'tibble: Simple Data Frames' 163 | notes: Imports 164 | url: https://tibble.tidyverse.org/ 165 | repository: https://CRAN.R-project.org/package=tibble 166 | authors: 167 | - family-names: Müller 168 | given-names: Kirill 169 | email: krlmlr+r@mailbox.org 170 | - family-names: Wickham 171 | given-names: Hadley 172 | email: hadley@rstudio.com 173 | year: '2023' 174 | -------------------------------------------------------------------------------- /docs/LICENSE.html: -------------------------------------------------------------------------------- 1 | 2 | MIT License • statcanR 6 | 7 | 8 |
    9 |
    53 | 54 | 55 | 56 |
    57 |
    58 | 61 | 62 |
    63 | 64 |

    Copyright (c) 2020 Thierry Warin ; Romain Le Duc

    65 |

    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

    66 |

    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

    67 |

    THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

    68 |
    69 | 70 |
    71 | 72 | 75 | 76 |
    77 | 78 | 79 | 80 |
    83 | 84 |
    85 |

    Site built with pkgdown 2.0.7.

    86 |
    87 | 88 |
    89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /docs/authors.html: -------------------------------------------------------------------------------- 1 | 2 | Authors and Citation • statcanR 6 | 7 | 8 |
    9 |
    53 | 54 | 55 | 56 |
    57 |
    58 |
    59 | 62 | 63 | 64 |
    • 65 |

      Thierry Warin. Author, maintainer. 66 |

      67 |
    • 68 |
    • 69 |

      Romain Le Duc. Author. 70 |

      71 |
    • 72 |
    73 |
    74 |
    75 |

    Citation

    76 | Source: DESCRIPTION 77 |
    78 |
    79 | 80 | 81 |

    Warin T, Le Duc R (2023). 82 | statcanR: Client for Statistics Canada's Open Economic Data. 83 | R package version 0.2.5, https://github.com/warint/statcanR/. 84 |

    85 |
    @Manual{,
     86 |   title = {statcanR: Client for Statistics Canada's Open Economic Data},
     87 |   author = {Thierry Warin and Romain {Le Duc}},
     88 |   year = {2023},
     89 |   note = {R package version 0.2.5},
     90 |   url = {https://github.com/warint/statcanR/},
     91 | }
    92 | 93 |
    94 | 95 |
    96 | 97 | 98 | 99 |
    102 | 103 |
    104 |

    Site built with pkgdown 2.0.7.

    105 |
    106 | 107 |
    108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /inst/README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | 5 | 6 | 7 | ```{r, include = FALSE} 8 | knitr::opts_chunk$set( 9 | collapse = TRUE, 10 | comment = "#>", 11 | fig.path = "man/figures/README-", 12 | out.width = "100%" 13 | ) 14 | ``` 15 | 16 | # statcanR 17 | 18 | 19 | 20 | 21 | [![Travis build status](https://travis-ci.com/warint/statcanR.svg?branch=master)](https://app.travis-ci.com/github/warint/statcanR) 22 | [![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/warint/statcanR?branch=master&svg=true)](https://ci.appveyor.com/project/warint/statcanR) 23 | [![Mentioned in Awesome](https://awesome.re/mentioned-badge.svg)](https://github.com/SNStatComp/awesome-official-statistics-software) 24 | [![CRAN status](https://www.r-pkg.org/badges/version/statcanR)](https://CRAN.R-project.org/package=statcanR) 25 | [![](https://cranlogs.r-pkg.org/badges/grand-total/statcanR?color=blue)](https://cran.r-project.org/package=statcanR) 26 | 27 | 28 | 29 | # Overview 30 | 31 | Easily connect to Statistics Canada's Web Data Service with R. Open economic data (formerly known as CANSIM tables, now identified by Product IDs (PID)) are accessible as a data frame, directly in the user's R environment. 32 | 33 | 34 | ## Shiny App : statcanR ExploR 35 | 36 | 37 | 38 | For people less comfortable with R and to allow more people to have access to our package, we have also developed a Shiny application.Through the same logic present in our package, researchers can retrieve data from Statistics Canada. 39 | 40 | statcanR EploR is available [[here]]( https://warin.ca/shiny/statcanr/) 41 | 42 | ## Installation 43 | 44 | The released version of statcanR package is accessible through CRAN and devtools. 45 | 46 | ``` r 47 | install.packages("statcanR") 48 | 49 | install.packages("devtools") 50 | devtools::install_github('warint/statcanR') 51 | ``` 52 | 53 | ## Example 54 | 55 | This section presents an example of how to use the `statcanR` R package and its function `statcan_data()` and `statcan_download_data()`. 56 | 57 | The following example is provided to illustrate how to use the functions. It consists in collecting some descriptive statistics about the Canadian Labour Force at the federal, provincial and industrial levels, on a monthly basis. 58 | 59 | With a simple web search 'statistics canada wages by industry metropolitan area monthly', the table number can easily be found on Statisitcs Canada's webpage. Here is below a figure that illustrates this example, such as '27-10-0014-01' for the Federal expenditures on science and technology, by socio-economic objectives. 60 | 61 | Once the table number is identified, the statcan_data() function is easy to use in order to collect the data, as following: 62 | 63 | ``` r 64 | library(statcanR) 65 | mydata <- statcan_data("27-10-0014-01","eng") 66 | ``` 67 | 68 | For the `statcan_download_data()` function there is no difference on how to use it, the only difference is that this function allow you to download the data in a csv file on top of having the data in your environment. 69 | 70 | ``` r 71 | library(statcanR) 72 | mydata <- statcan_download_data("27-10-0014-01","eng") 73 | ``` 74 | 75 | ### Video Tutorial 76 | 77 | Tutorial made by Professor Charles Saunders, Director of Master of Financial 78 | Economics Program at Western University [biography](https://economics.uwo.ca/people/faculty/saunders.html) 79 | 80 | Thanks! 81 | 82 | 83 | 84 | 85 | ### Statistics Canada Open Licence 86 | 87 | This licence is issued on behalf of Her Majesty the Queen in Right of Canada, as represented by the Minister for Statistics Canada ("Statistics Canada") to you (an individual or a legal entity that you are authorized to represent). 88 | 89 | Statistics Canada may modify this licence at any time, and such modifications shall be effective immediately upon posting of the modified licence on the Statistics Canada website. Your use of the Information will be governed by the terms of the licence in force as of the date and time you accessed the Information. 90 | 91 | Please refer to the [terms of licence](https://www.statcan.gc.ca/eng/reference/licence) before using the Information. 92 | 93 | 94 | ##### Acknowledgment of Source according to Statistics Canada Open Licence Agreement 95 | 96 | Statistics Canada has a specific procedure regarding the ackowledgment of source : 97 | 98 | You shall include and maintain the following notice on all licensed rights of the Information: 99 | 100 | Source: Statistics Canada, name of product, reference date. Reproduced and distributed on an "as is" basis with the permission of Statistics Canada. 101 | 102 | Where any Information is contained within a Value-added Product, you shall include on such Value-added Product the following notice: 103 | 104 | Adapted from Statistics Canada, name of product, reference date. This does not constitute an endorsement by Statistics Canada of this product. 105 | 106 | ### Cite statcanR 107 | 108 | To cite statcanR package in your work: 109 | 110 | Warin, T. (2024). Access Statistics Canada’s Open Economic Data for Statistics and Data Science Courses. Technology Innovations in Statistics Education, 15(1). http://dx.doi.org/10.5070/T5.1868 Retrieved from https://escholarship.org/uc/item/9jr7k5hp 111 | 112 | ``` r 113 | @article{warin_access_2024, 114 | title = {Access {Statistics} {Canada}’s {Open} {Economic} {Data} for {Statistics} and {Data} {Science} {Courses}}, 115 | volume = {15}, 116 | url = {https://escholarship.org/uc/item/9jr7k5hp}, 117 | doi = {10.5070/T5.1868}, 118 | abstract = {This article is about the two conflicting goals when teaching statistics or data science courses based on real-world data in a business school environment. We propose to look at structured socio-economic data about the Canadian economy. Canada was ranked 8th in 2017 by Open Data Watch (Government of Canada) for its data accessibility policy. Statistics Canada offers several ways to access data across its over 11,000 data tables. We built an R package to ease access to Statistics Canada's open economic data. With this package, we offer students another option to collect data about the Canadian economy.}, 119 | language = {en}, 120 | number = {1}, 121 | urldate = {2024-01-17}, 122 | journal = {Technology Innovations in Statistics Education}, 123 | author = {Warin, Thierry}, 124 | month = jan, 125 | year = {2024}, 126 | file = {Full Text PDF:/Users/thierrywarin/Zotero/storage/7LNXFPKL/Warin - 2024 - Access Statistics Canada’s Open Economic Data for .pdf:application/pdf}, 127 | } 128 | ``` 129 | 130 | ### Acknowledgments 131 | 132 | The authors would like to thank the Center for Interuniversity Research and Analysis of Organizations (CIRANO, Montreal) for its support, as well as Thibault Senegas, Marine Leroi and Martin Paquette. However, errors and omissions are ours. 133 | -------------------------------------------------------------------------------- /docs/news/index.html: -------------------------------------------------------------------------------- 1 | 2 | Changelog • statcanR 6 | 7 | 8 |
    9 |
    53 | 54 | 55 | 56 |
    57 |
    58 | 62 | 63 |
    64 | 65 |
    • We have corrected statcan_search() function by removing top level code. You can now install statcanR package without an internet connection
    • 66 |
    67 |
    68 | 69 |
    • we have added the function statcan_search() to identify economic data tables available on Statistics Canada’s website.
    • 70 |
    71 |
    72 | 73 |
    • we have modified the function to get an informative message if the table is not available instead of having an error message.
    • 74 |
    75 |
    76 | 77 |
    • we replaced utils::read.csv by readr::read_csv to fix a random bug with some metadata tables.
    • 78 |
    79 |
    80 | 81 |
    • In this version, we have changed the name of the functions by withdrawing the sqs mentions. The old functions will remain available until the next update (deprecated).
    • 82 |
    83 |
    84 | 85 | 88 | 89 |
    90 | 91 | 92 |
    95 | 96 |
    97 |

    Site built with pkgdown 2.0.7.

    98 |
    99 | 100 |
    101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /docs/reference/statcan_data.html: -------------------------------------------------------------------------------- 1 | 2 | statcanR — statcan_data • statcanR 6 | 7 | 8 |
    9 |
    53 | 54 | 55 | 56 |
    57 |
    58 | 63 | 64 |
    65 |

    Easily connect to Statistics Canada's Web Data Service with R. Open economic data (formerly known as CANSIM tables, now identified by Product IDs (PID)) are accessible as a data frame, directly in the user's R environment.

    66 |
    67 | 68 |
    69 |
    statcan_data(tableNumber, lang)
    70 |
    71 | 72 |
    73 |

    Arguments

    74 |
    tableNumber
    75 |

    The table number of the Statistics Canada data table

    76 | 77 | 78 |
    lang
    79 |

    The language wanted

    80 | 81 |
    82 |
    83 |

    Value

    84 | 85 | 86 |

    The output will be a data table representing the data associated with the chosen table number.

    87 |
    88 |
    89 |

    Details

    90 |

    The 91 | statcan_data() function has 2 arguments to fulfill to get data: tableNumber & lang.

    92 | 93 |

    The tableNumber argument simply refers to the table number of the Statistics Canada data table a user wants to collect, 94 | such as '27-10-0014-01' for the Federal expenditures on science and technology, by socio-economic objectives, as an example.

    95 | 96 |

    To get the table number: https://www150.statcan.gc.ca/n1/en/type/data.

    97 |

    The second argument, lang, refers to the language. As Canada is a bilingual country, Statistics Canada displays all the economic data in both languages. 98 | Therefore, users can choose to collect satistics data tables in French or English by setting the lang argument with c('fra', 'eng').

    99 |
    100 | 101 |
    102 |

    Examples

    103 |
    #mydata <- statcan_data('27-10-0014-01', 'eng')
    104 | 
    105 | 
    106 | 
    107 |
    108 |
    109 | 112 |
    113 | 114 | 115 |
    118 | 119 |
    120 |

    Site built with pkgdown 2.0.7.

    121 |
    122 | 123 |
    124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # statcanR 5 | 6 | 7 | 8 | [![AppVeyor build 9 | status](https://ci.appveyor.com/api/projects/status/github/warint/statcanR?branch=master&svg=true)](https://ci.appveyor.com/project/warint/statcanR) 10 | [![Mentioned in 11 | Awesome](https://awesome.re/mentioned-badge.svg)](https://github.com/SNStatComp/awesome-official-statistics-software) 12 | [![CRAN 13 | status](https://www.r-pkg.org/badges/version/statcanR)](https://CRAN.R-project.org/package=statcanR) 14 | [![](https://cranlogs.r-pkg.org/badges/grand-total/statcanR?color=blue)](https://cran.r-project.org/package=statcanR) 15 | 16 | 17 | 18 | # Overview 19 | 20 | Easily connect to Statistics Canada’s Web Data Service with R. Find and 21 | access open economic data (formerly known as CANSIM tables, now identified by 22 | Product IDs (PID)) which are accessible as a data frame, directly in the 23 | user’s R environment. 24 | 25 | 26 | 27 | ## Shiny App : statcanR ExploR 28 | 29 | 30 | 31 | For people less comfortable with R and to allow more people to have 32 | access to our package, we have also developed a Shiny 33 | application.Through the same logic present in our package, researchers 34 | can retrieve data from Statistics Canada. 35 | 36 | statcanR ExploR is available [\[here\]](https://warin.ca/shiny/statcanr/) 37 | 38 | ## Installation 39 | 40 | The released version of statcanR package is accessible through CRAN and 41 | devtools. 42 | 43 | ``` r 44 | install.packages("statcanR") 45 | 46 | install.packages("devtools") 47 | devtools::install_github('warint/statcanR') 48 | ``` 49 | 50 | ## Example 51 | 52 | This section presents an example of how to use the `statcanR` R package 53 | and its functions: `statcan_search()`, `statcan_data()`, and 54 | `statcan_download_data()`. 55 | 56 | The following example is provided to illustrate how to use the 57 | functions. It consists in collecting some descriptive statistics about 58 | the Canadian Labour Force at the federal, provincial and industrial 59 | levels, on a monthly basis. 60 | 61 | To identify a relevant table, the statcan_search() function can be used 62 | by using a keyword or set of keywords and specifying the language in which the 63 | data will be presented (English or French). Below is an example that reveals 64 | the data tables we could be interested in: 65 | 66 | ``` r 67 | library(statcanR) 68 | statcan_search(c("federal","expenditures","objectives"),"eng") 69 | ``` 70 | 71 | Notice that for each corresponding table, the unique table number identifier is 72 | also presented. Let's focus the first table out of the two that appear, which 73 | contains data on Federal expenditures on science and technology, 74 | by socio-economic objectives. Once this table number is identified 75 | (‘27-10-0014-01’), the statcan_data() function is easy 76 | to use in order to collect the data, as following: 77 | 78 | ``` r 79 | library(statcanR) 80 | mydata <- statcan_data("27-10-0014-01","eng") 81 | ``` 82 | 83 | For the `statcan_download_data()` function there is no difference on how 84 | to use it, the only difference is that this function allow you to 85 | download the data in a csv file on top of having the data in your 86 | environment. 87 | 88 | ``` r 89 | library(statcanR) 90 | mydata <- statcan_download_data("27-10-0014-01","eng") 91 | ``` 92 | 93 | ### Video Tutorial 94 | 95 | Tutorial made by Professor Charles Saunders, Director of Master of 96 | Financial Economics Program at Western University 97 | [biography](https://economics.uwo.ca/people/faculty/saunders.html) 98 | 99 | Thanks! 100 | 101 | 102 | 103 | ### Statistics Canada Open Licence 104 | 105 | This licence is issued on behalf of His Majesty the King in Right of 106 | Canada, as represented by the Minister for Statistics Canada 107 | (“Statistics Canada”) to you (an individual or a legal entity that you 108 | are authorized to represent). 109 | 110 | Statistics Canada may modify this licence at any time, and such 111 | modifications shall be effective immediately upon posting of the 112 | modified licence on the Statistics Canada website. Your use of the 113 | Information will be governed by the terms of the licence in force as of 114 | the date and time you accessed the Information. 115 | 116 | Please refer to the [terms of 117 | licence](https://www.statcan.gc.ca/eng/reference/licence) before using 118 | the Information. 119 | 120 | ##### Acknowledgment of Source according to Statistics Canada Open Licence Agreement 121 | 122 | Statistics Canada has a specific procedure regarding the acknowledgment 123 | of source : 124 | 125 | You shall include and maintain the following notice on all licensed 126 | rights of the Information: 127 | 128 | Source: Statistics Canada, name of product, reference date. Reproduced and distributed on an "as is" basis with the permission of Statistics Canada. 129 | 130 | Where any Information is contained within a Value-added Product, you 131 | shall include on such Value-added Product the following notice: 132 | 133 | Adapted from Statistics Canada, name of product, reference date. This does not constitute an endorsement by Statistics Canada of this product. 134 | 135 | ### Cite statcanR 136 | 137 | To cite statcanR package in your work: 138 | 139 | Warin, T. (2024). Access Statistics Canada’s Open Economic Data for Statistics and Data Science Courses. Technology Innovations in Statistics Education, 15(1). http://dx.doi.org/10.5070/T5.1868 Retrieved from https://escholarship.org/uc/item/9jr7k5hp 140 | 141 | ``` r 142 | @article{warin_access_2024, 143 | title = {Access {Statistics} {Canada}’s {Open} {Economic} {Data} for {Statistics} and {Data} {Science} {Courses}}, 144 | volume = {15}, 145 | url = {https://escholarship.org/uc/item/9jr7k5hp}, 146 | doi = {10.5070/T5.1868}, 147 | abstract = {This article is about the two conflicting goals when teaching statistics or data science courses based on real-world data in a business school environment. We propose to look at structured socio-economic data about the Canadian economy. Canada was ranked 8th in 2017 by Open Data Watch (Government of Canada) for its data accessibility policy. Statistics Canada offers several ways to access data across its over 11,000 data tables. We built an R package to ease access to Statistics Canada's open economic data. With this package, we offer students another option to collect data about the Canadian economy.}, 148 | language = {en}, 149 | number = {1}, 150 | urldate = {2024-01-17}, 151 | journal = {Technology Innovations in Statistics Education}, 152 | author = {Warin, Thierry}, 153 | month = jan, 154 | year = {2024}, 155 | file = {Full Text PDF:/Users/thierrywarin/Zotero/storage/7LNXFPKL/Warin - 2024 - Access Statistics Canada’s Open Economic Data for .pdf:application/pdf}, 156 | } 157 | ``` 158 | 159 | ### Acknowledgments 160 | 161 | A previous version of this package was developed with Romain Le Duc. This version has benefitted from Thibault Senegas's contribution. The author would like to thank the Center for Interuniversity Research and Analysis of Organizations (CIRANO, Montreal) for its support, as well as Thibault Senegas, Jeremy Schneider, Marine Leroi, Martin Paquette and Romain Le Duc. However, errors and omissions are his. 162 | 163 | 164 | ### Contributing to the package 165 | #### Bug reports 166 | 167 | When you file a bug report, please spend some time making it easy for me to follow and reproduce. The more time you spend on making the bug report coherent, the more time I can dedicate to investigate the bug as opposed to the bug report. 168 | 169 | ##### Contributing to the package development 170 | 171 | To get started, consider either adding a new example or enhancing the existing documentation. 172 | 173 | If you're interested in submitting a Pull Request to include your own functions, please include the following: 174 | 175 | - The code for the new function(s), complete with roxygen annotations and sample usage. 176 | - A dedicated section in the relevant vignette that explains how to utilize the new function. 177 | 178 | To ensure your changes are compliant, run rhub::check_for_cran() using rhub. After submission, your Pull Request will undergo automated evaluation via GitHub Actions, allowing you to monitor for any issues. 179 | 180 | -------------------------------------------------------------------------------- /vignettes/statCanR.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "statCanR" 3 | author: "Thierry Warin" 4 | data: "`r Sys.Date()`" 5 | output: rmarkdown::html_vignette 6 | vignette: > 7 | %\VignetteIndexEntry{statCanR} 8 | %\VignetteEngine{knitr::rmarkdown} 9 | %\VignetteEncoding{UTF-8} 10 | --- 11 | 12 | ```{r, include = FALSE} 13 | knitr::opts_chunk$set( 14 | collapse = TRUE, 15 | comment = "#>" 16 | ) 17 | ``` 18 | 19 | ```{r setup} 20 | library(statcanR) 21 | ``` 22 | 23 | 24 | ## Overview 25 | 26 | statcanR provides the R user with a consistent process to identify and collect data from Statistics Canada's data portal. It allows users to search for and access all of Statistics Canada' open economic data (formerly known as CANSIM tables) now identified by product IDs (PID) by the new Statistics Canada's Web Data Service: . 27 | 28 | ## Quick start 29 | 30 | First, install statcanR: 31 | 32 | ```{r, eval=FALSE} 33 | devtools::install_github("warint/statcanR") 34 | ``` 35 | 36 | 37 | Next, call statcanR to make sure everything is installed correctly. 38 | 39 | ```{r} 40 | library(statcanR) 41 | ``` 42 | 43 | # Practical usage 44 | 45 | This section presents an example of how to use the statcanR R package and its functions: statcan_search() and statcan_data(). 46 | 47 | 48 | The following example is provided to illustrate how to use these functions. It consists of collecting some descriptive statistics about the Canadian labour force at the federal, provincial and industrial levels, on a monthly basis. 49 | 50 | To identify a relevant table, the statcan_search() function can be used 51 | by using a keyword or set of keywords, depending on the language the user wishes to search in (between English and French). Below is an example that reveals 52 | the data tables we could be interested in: 53 | 54 | ```{r, eval=FALSE} 55 | # Identify with statcan_search() function 56 | statcan_search(c("federal","expenditures"),"eng") 57 | ``` 58 | 59 | 60 | Notice that for each corresponding table, the unique table number identifier is also presented. Let's focus on the first table out of the two that appear, which contains data on Federal expenditures on science and technology, by socio-economic objectives. Once this table number is identified 61 | (‘27-10-0014-01’), the statcan_data() function is easy to use in order to collect the data, as following: 62 | 63 | ```{r, eval=FALSE} 64 | # Get data with statcan_data function 65 | mydata <- statcan_download_data("27-10-0014-01", "eng") 66 | ``` 67 | 68 | Should you want the same data in French, just replace the argument at the end of the function with "fra". 69 | 70 | ## Code architecture 71 | 72 | This section describes the code architecture of the statcanR package. 73 | 74 | The statcan_search() function has 2 arguments: 75 | 76 | 1. keywords 77 | 2. lang 78 | 79 | The 'keywords' argument is useful for identifying what kind of open economic data Statistics Canada has available for users. It can take as inputs either a single word (i.e., statcan_search("expenditures")) or a vector of multiple keywords (such as: statcan_search(c("expenditures","federal","objectives"))). 80 | 81 | The second argument, 'lang', refers to the language. As Canada is a bilingual country, Statistics Canada displays all the economic data in both languages. Therefore, users can see what data tables are available in French or English by setting the lang argument with c("fra", "eng"). 82 | 83 | 84 | 85 | 86 | For all data tables that contain these words in either their title or description, the resulting output will include four pieces of information: The name of the data table, its unique table number identifier, the description, and the release date. 87 | In details, the statcan_download_data() function has 2 arguments: 88 | 89 | 1. tableNumber 90 | 2. lang 91 | 92 | 93 | The 'tableNumber' argument simply refers to the table number of the Statistics Canada data table a user wants to collect, such as '27-10-0014-01' for the Federal expenditures on science and technology, by socio-economic objectives, as an example. 94 | 95 | 96 | Just as in the statcan_search() command, 'lang', refers to the language, and can be set to "eng" for English or "fra" for French. Therefore, users can choose to collect satistics data tables in French or English by setting the lang argument with c("fra", "eng"). 97 | 98 | The code architecture of the statcan_download_data() function is as follows. The first step if to clean the table number in order to align it with the official typology of Statistics Canada's Web Data Service. The second step is to create a temporary folder where all the data wrangling operations are performed. The third step is to check and select the correct language. The fourth step is to define the right URL where the actual data table is stored and then to download the .Zip container. The fifth step is to unzip the previously downloaded .Zip file to extract the data and metadata from the .csv files. The final step is to load the statistics data into a data frame called 'data' and to add the official table indicator name in the new 'INDICATOR' column. 99 | 100 | 101 | To be more precise about the functions, below is some further code description: 102 | 103 | ### statcan_search() 104 | 105 | - ` keyword_regex <- paste0("(", paste(keywords, collapse = "|"), ")", collapse = ".*")`: 106 | The first step is to paste (either individually or in vector format) the keywords the user is interested in 107 | 108 | - ` matches <- apply(statcan_data, 1, function(row) {` 109 | ` all(sapply(keywords, function(x) {` 110 | ` grepl(x, paste(as.character(row), collapse = " "))` 111 | ` }))` 112 | ` }) `: 113 | Next, the matching relies on the sapply function, which is applied to any character string in a row of a given observation. Therefore, the "keyword" could be found in the title column or the description column (technically, it could even be in the "release date" or "id" columns). 114 | 115 | - ` filtered_data <- statcan_data[matches, ]` 116 | The third step takes only the data where matches were found. 117 | 118 | - ` datatable(filtered_data, options = list(pageLength = 10))` 119 | Finally, the datatable command presents the filtered data in a clean table. 120 | 121 | 122 | 123 | ### statcan_download_data() 124 | 125 | - `tableNumber <- gsub("-", "", substr(tableNumber, 1, nchar(tableNumber)-2))`: 126 | The first step is to clean the table number provided by the user in order to collect the overall data table related to the specific indicator the user is interested in. In fact, each indicator is an excerpt of the overall table. 127 | In addition, following the new Statistics Canada's Web Data Service, the URL typology defined by REST API is stored in csv files by table numbers without a '-'. Also, the last 2 digits after the last '-' refer to the specific excerpt of the original table. 128 | Therefore, following the Statistics Canada Web Data Service's typology, the function first removes the '-' and the last 2 digits from the user's selection. 129 | 130 | - `if(lang == "eng")` | `if(lang == "fra")`: 131 | The second step is the 'if statement' to get the data in the correct language. 132 | 133 | - `urlFra <- paste0("https://www150.statcan.gc.ca/n1/fr/tbl/csv/", tableNumber, "-fra.zip")`: 134 | The third step is to create the correct url in order to download the respective .Zip file from the Statistics Canada Web Data Service. 135 | 136 | - `download(urlFra, download_dir, mode = "wb")`: 137 | The fourth step is a simple downloading function that extracts .Zip file and download it into a temporary folder. 138 | 139 | - `unzip(zipfile = download_dir, exdir = unzip_dir)`: 140 | The fifth step consists in unzipping the .Zip file. The unzipping process gives access to two different .csv files, such as the overall data table and the metadata table. 141 | 142 | - `data.table::fread(csv_file)`: 143 | The sixth step consists in loading the data table into a unique data frame. The fread() function from the data.table package is used for its higher performance. 144 | 145 | - `data$INDICATOR <- as.character(0)` and `data$INDICATOR <- as.character(read.csv(paste0(path,"/temp/", tableNumber, "_MetaData.csv"))[1,1])`: 146 | The seventh step of the statcan_data() function consists in adding the name of the table from the metadata table. 147 | 148 | - `unlink(tempdir())`: 149 | The eighth step deletes the temporary folder used to download, unzip, extract and load the data. 150 | 151 | - `return(Data)`: 152 | Finally, the last step of the statcan_data() function allows to return the value into the user's environment. 153 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /docs/reference/statcan_download_data.html: -------------------------------------------------------------------------------- 1 | 2 | statcanR download data function — statcan_download_data • statcanR 6 | 7 | 8 |
    9 |
    53 | 54 | 55 | 56 |
    57 |
    58 | 63 | 64 |
    65 |

    statcanR download data function

    66 |
    67 | 68 |
    69 |
    statcan_download_data(tableNumber, lang)
    70 |
    71 | 72 |
    73 |

    Arguments

    74 |
    tableNumber
    75 |

    The table number of the Statistics Canada data table

    76 | 77 | 78 |
    lang
    79 |

    The language wanted

    80 | 81 |
    82 |
    83 |

    Value

    84 | 85 | 86 |

    The output will be a data table and csv file representing the data associated with the chosen table number.

    87 |
    88 | 89 |
    90 |

    Examples

    91 |
    mydata <- statcan_data('27-10-0014-01', 'eng')
     92 | #> statcanR: downloading remote table.
     93 | #> Warning: One or more parsing issues, call `problems()` on your data frame for details,
     94 | #> e.g.:
     95 | #>   dat <- vroom(...)
     96 | #>   problems(dat)
     97 | #> Rows: 61 Columns: 10
     98 | #> ── Column specification ────────────────────────────────────────────────────────
     99 | #> Delimiter: ","
    100 | #> chr  (8): Cube Title, Product Id, CANSIM Id, URL, Cube Notes, Archive Status...
    101 | #> num  (1): Total number of dimensions
    102 | #> date (1): End Reference Period
    103 | #> 
    104 | #>  Use `spec()` to retrieve the full column specification for this data.
    105 | #>  Specify the column types or set `show_col_types = FALSE` to quiet this message.
    106 | 
    107 |
    108 |
    109 | 112 |
    113 | 114 | 115 |
    118 | 119 |
    120 |

    Site built with pkgdown 2.0.7.

    121 |
    122 | 123 |
    124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /docs/pkgdown.css: -------------------------------------------------------------------------------- 1 | /* Sticky footer */ 2 | 3 | /** 4 | * Basic idea: https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/ 5 | * Details: https://github.com/philipwalton/solved-by-flexbox/blob/master/assets/css/components/site.css 6 | * 7 | * .Site -> body > .container 8 | * .Site-content -> body > .container .row 9 | * .footer -> footer 10 | * 11 | * Key idea seems to be to ensure that .container and __all its parents__ 12 | * have height set to 100% 13 | * 14 | */ 15 | 16 | html, body { 17 | height: 100%; 18 | } 19 | 20 | body { 21 | position: relative; 22 | } 23 | 24 | body > .container { 25 | display: flex; 26 | height: 100%; 27 | flex-direction: column; 28 | } 29 | 30 | body > .container .row { 31 | flex: 1 0 auto; 32 | } 33 | 34 | footer { 35 | margin-top: 45px; 36 | padding: 35px 0 36px; 37 | border-top: 1px solid #e5e5e5; 38 | color: #666; 39 | display: flex; 40 | flex-shrink: 0; 41 | } 42 | footer p { 43 | margin-bottom: 0; 44 | } 45 | footer div { 46 | flex: 1; 47 | } 48 | footer .pkgdown { 49 | text-align: right; 50 | } 51 | footer p { 52 | margin-bottom: 0; 53 | } 54 | 55 | img.icon { 56 | float: right; 57 | } 58 | 59 | /* Ensure in-page images don't run outside their container */ 60 | .contents img { 61 | max-width: 100%; 62 | height: auto; 63 | } 64 | 65 | /* Fix bug in bootstrap (only seen in firefox) */ 66 | summary { 67 | display: list-item; 68 | } 69 | 70 | /* Typographic tweaking ---------------------------------*/ 71 | 72 | .contents .page-header { 73 | margin-top: calc(-60px + 1em); 74 | } 75 | 76 | dd { 77 | margin-left: 3em; 78 | } 79 | 80 | /* Section anchors ---------------------------------*/ 81 | 82 | a.anchor { 83 | display: none; 84 | margin-left: 5px; 85 | width: 20px; 86 | height: 20px; 87 | 88 | background-image: url(./link.svg); 89 | background-repeat: no-repeat; 90 | background-size: 20px 20px; 91 | background-position: center center; 92 | } 93 | 94 | h1:hover .anchor, 95 | h2:hover .anchor, 96 | h3:hover .anchor, 97 | h4:hover .anchor, 98 | h5:hover .anchor, 99 | h6:hover .anchor { 100 | display: inline-block; 101 | } 102 | 103 | /* Fixes for fixed navbar --------------------------*/ 104 | 105 | .contents h1, .contents h2, .contents h3, .contents h4 { 106 | padding-top: 60px; 107 | margin-top: -40px; 108 | } 109 | 110 | /* Navbar submenu --------------------------*/ 111 | 112 | .dropdown-submenu { 113 | position: relative; 114 | } 115 | 116 | .dropdown-submenu>.dropdown-menu { 117 | top: 0; 118 | left: 100%; 119 | margin-top: -6px; 120 | margin-left: -1px; 121 | border-radius: 0 6px 6px 6px; 122 | } 123 | 124 | .dropdown-submenu:hover>.dropdown-menu { 125 | display: block; 126 | } 127 | 128 | .dropdown-submenu>a:after { 129 | display: block; 130 | content: " "; 131 | float: right; 132 | width: 0; 133 | height: 0; 134 | border-color: transparent; 135 | border-style: solid; 136 | border-width: 5px 0 5px 5px; 137 | border-left-color: #cccccc; 138 | margin-top: 5px; 139 | margin-right: -10px; 140 | } 141 | 142 | .dropdown-submenu:hover>a:after { 143 | border-left-color: #ffffff; 144 | } 145 | 146 | .dropdown-submenu.pull-left { 147 | float: none; 148 | } 149 | 150 | .dropdown-submenu.pull-left>.dropdown-menu { 151 | left: -100%; 152 | margin-left: 10px; 153 | border-radius: 6px 0 6px 6px; 154 | } 155 | 156 | /* Sidebar --------------------------*/ 157 | 158 | #pkgdown-sidebar { 159 | margin-top: 30px; 160 | position: -webkit-sticky; 161 | position: sticky; 162 | top: 70px; 163 | } 164 | 165 | #pkgdown-sidebar h2 { 166 | font-size: 1.5em; 167 | margin-top: 1em; 168 | } 169 | 170 | #pkgdown-sidebar h2:first-child { 171 | margin-top: 0; 172 | } 173 | 174 | #pkgdown-sidebar .list-unstyled li { 175 | margin-bottom: 0.5em; 176 | } 177 | 178 | /* bootstrap-toc tweaks ------------------------------------------------------*/ 179 | 180 | /* All levels of nav */ 181 | 182 | nav[data-toggle='toc'] .nav > li > a { 183 | padding: 4px 20px 4px 6px; 184 | font-size: 1.5rem; 185 | font-weight: 400; 186 | color: inherit; 187 | } 188 | 189 | nav[data-toggle='toc'] .nav > li > a:hover, 190 | nav[data-toggle='toc'] .nav > li > a:focus { 191 | padding-left: 5px; 192 | color: inherit; 193 | border-left: 1px solid #878787; 194 | } 195 | 196 | nav[data-toggle='toc'] .nav > .active > a, 197 | nav[data-toggle='toc'] .nav > .active:hover > a, 198 | nav[data-toggle='toc'] .nav > .active:focus > a { 199 | padding-left: 5px; 200 | font-size: 1.5rem; 201 | font-weight: 400; 202 | color: inherit; 203 | border-left: 2px solid #878787; 204 | } 205 | 206 | /* Nav: second level (shown on .active) */ 207 | 208 | nav[data-toggle='toc'] .nav .nav { 209 | display: none; /* Hide by default, but at >768px, show it */ 210 | padding-bottom: 10px; 211 | } 212 | 213 | nav[data-toggle='toc'] .nav .nav > li > a { 214 | padding-left: 16px; 215 | font-size: 1.35rem; 216 | } 217 | 218 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 219 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 220 | padding-left: 15px; 221 | } 222 | 223 | nav[data-toggle='toc'] .nav .nav > .active > a, 224 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 225 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 226 | padding-left: 15px; 227 | font-weight: 500; 228 | font-size: 1.35rem; 229 | } 230 | 231 | /* orcid ------------------------------------------------------------------- */ 232 | 233 | .orcid { 234 | font-size: 16px; 235 | color: #A6CE39; 236 | /* margins are required by official ORCID trademark and display guidelines */ 237 | margin-left:4px; 238 | margin-right:4px; 239 | vertical-align: middle; 240 | } 241 | 242 | /* Reference index & topics ----------------------------------------------- */ 243 | 244 | .ref-index th {font-weight: normal;} 245 | 246 | .ref-index td {vertical-align: top; min-width: 100px} 247 | .ref-index .icon {width: 40px;} 248 | .ref-index .alias {width: 40%;} 249 | .ref-index-icons .alias {width: calc(40% - 40px);} 250 | .ref-index .title {width: 60%;} 251 | 252 | .ref-arguments th {text-align: right; padding-right: 10px;} 253 | .ref-arguments th, .ref-arguments td {vertical-align: top; min-width: 100px} 254 | .ref-arguments .name {width: 20%;} 255 | .ref-arguments .desc {width: 80%;} 256 | 257 | /* Nice scrolling for wide elements --------------------------------------- */ 258 | 259 | table { 260 | display: block; 261 | overflow: auto; 262 | } 263 | 264 | /* Syntax highlighting ---------------------------------------------------- */ 265 | 266 | pre, code, pre code { 267 | background-color: #f8f8f8; 268 | color: #333; 269 | } 270 | pre, pre code { 271 | white-space: pre-wrap; 272 | word-break: break-all; 273 | overflow-wrap: break-word; 274 | } 275 | 276 | pre { 277 | border: 1px solid #eee; 278 | } 279 | 280 | pre .img, pre .r-plt { 281 | margin: 5px 0; 282 | } 283 | 284 | pre .img img, pre .r-plt img { 285 | background-color: #fff; 286 | } 287 | 288 | code a, pre a { 289 | color: #375f84; 290 | } 291 | 292 | a.sourceLine:hover { 293 | text-decoration: none; 294 | } 295 | 296 | .fl {color: #1514b5;} 297 | .fu {color: #000000;} /* function */ 298 | .ch,.st {color: #036a07;} /* string */ 299 | .kw {color: #264D66;} /* keyword */ 300 | .co {color: #888888;} /* comment */ 301 | 302 | .error {font-weight: bolder;} 303 | .warning {font-weight: bolder;} 304 | 305 | /* Clipboard --------------------------*/ 306 | 307 | .hasCopyButton { 308 | position: relative; 309 | } 310 | 311 | .btn-copy-ex { 312 | position: absolute; 313 | right: 0; 314 | top: 0; 315 | visibility: hidden; 316 | } 317 | 318 | .hasCopyButton:hover button.btn-copy-ex { 319 | visibility: visible; 320 | } 321 | 322 | /* headroom.js ------------------------ */ 323 | 324 | .headroom { 325 | will-change: transform; 326 | transition: transform 200ms linear; 327 | } 328 | .headroom--pinned { 329 | transform: translateY(0%); 330 | } 331 | .headroom--unpinned { 332 | transform: translateY(-100%); 333 | } 334 | 335 | /* mark.js ----------------------------*/ 336 | 337 | mark { 338 | background-color: rgba(255, 255, 51, 0.5); 339 | border-bottom: 2px solid rgba(255, 153, 51, 0.3); 340 | padding: 1px; 341 | } 342 | 343 | /* vertical spacing after htmlwidgets */ 344 | .html-widget { 345 | margin-bottom: 10px; 346 | } 347 | 348 | /* fontawesome ------------------------ */ 349 | 350 | .fab { 351 | font-family: "Font Awesome 5 Brands" !important; 352 | } 353 | 354 | /* don't display links in code chunks when printing */ 355 | /* source: https://stackoverflow.com/a/10781533 */ 356 | @media print { 357 | code a:link:after, code a:visited:after { 358 | content: ""; 359 | } 360 | } 361 | 362 | /* Section anchors --------------------------------- 363 | Added in pandoc 2.11: https://github.com/jgm/pandoc-templates/commit/9904bf71 364 | */ 365 | 366 | div.csl-bib-body { } 367 | div.csl-entry { 368 | clear: both; 369 | } 370 | .hanging-indent div.csl-entry { 371 | margin-left:2em; 372 | text-indent:-2em; 373 | } 374 | div.csl-left-margin { 375 | min-width:2em; 376 | float:left; 377 | } 378 | div.csl-right-inline { 379 | margin-left:2em; 380 | padding-left:1em; 381 | } 382 | div.csl-indent { 383 | margin-left: 2em; 384 | } 385 | -------------------------------------------------------------------------------- /docs/reference/statcan_search.html: -------------------------------------------------------------------------------- 1 | 2 | Searching function for statcanR — statcan_search • statcanR 9 | 10 | 11 |
    12 |
    56 | 57 | 58 | 59 |
    60 |
    61 | 66 | 67 |
    68 |

    The statcan_search() function has 2 arguments to fulfill to find a database: keywords and lang. 69 | The keywords argument refers to words that can be found in either the title or the description of the database. For example, inserting the keywords 70 | "economy","export",and "link" will bring up the title, table id, description, and release date for databases that include these keywords. In this case, only one data table ("Supply and use tables, link-1997 level") 71 | would be returned as it is the only data table containing all three words.

    72 |
    73 | 74 |
    75 |
    statcan_search(keywords, lang)
    76 |
    77 | 78 |
    79 |

    Arguments

    80 |
    keywords
    81 |

    The words that appear in the title or description of the data table

    82 | 83 | 84 |
    lang
    85 |

    The language wanted

    86 | 87 |
    88 |
    89 |

    Value

    90 | 91 | 92 |

    The output will be the title, id, description, and release date of a table

    93 |
    94 |
    95 |

    Details

    96 |

    Easily connect to Statistics Canada's Web Data Service with R. Open economic data (formerly known as CANSIM tables, now identified by Product IDs (PID)) are accessible as a data frame, directly in the user's R environment.

    97 |
    98 | 99 |
    100 |

    Examples

    101 |
    statcan_search(c("economy","export","link"),"eng")
    102 | 
    103 |
    104 |
    105 |
    106 | 109 |
    110 | 111 | 112 |
    115 | 116 |
    117 |

    Site built with pkgdown 2.0.7.

    118 |
    119 | 120 |
    121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | -------------------------------------------------------------------------------- /docs/docsearch.css: -------------------------------------------------------------------------------- 1 | /* Docsearch -------------------------------------------------------------- */ 2 | /* 3 | Source: https://github.com/algolia/docsearch/ 4 | License: MIT 5 | */ 6 | 7 | .algolia-autocomplete { 8 | display: block; 9 | -webkit-box-flex: 1; 10 | -ms-flex: 1; 11 | flex: 1 12 | } 13 | 14 | .algolia-autocomplete .ds-dropdown-menu { 15 | width: 100%; 16 | min-width: none; 17 | max-width: none; 18 | padding: .75rem 0; 19 | background-color: #fff; 20 | background-clip: padding-box; 21 | border: 1px solid rgba(0, 0, 0, .1); 22 | box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .175); 23 | } 24 | 25 | @media (min-width:768px) { 26 | .algolia-autocomplete .ds-dropdown-menu { 27 | width: 175% 28 | } 29 | } 30 | 31 | .algolia-autocomplete .ds-dropdown-menu::before { 32 | display: none 33 | } 34 | 35 | .algolia-autocomplete .ds-dropdown-menu [class^=ds-dataset-] { 36 | padding: 0; 37 | background-color: rgb(255,255,255); 38 | border: 0; 39 | max-height: 80vh; 40 | } 41 | 42 | .algolia-autocomplete .ds-dropdown-menu .ds-suggestions { 43 | margin-top: 0 44 | } 45 | 46 | .algolia-autocomplete .algolia-docsearch-suggestion { 47 | padding: 0; 48 | overflow: visible 49 | } 50 | 51 | .algolia-autocomplete .algolia-docsearch-suggestion--category-header { 52 | padding: .125rem 1rem; 53 | margin-top: 0; 54 | font-size: 1.3em; 55 | font-weight: 500; 56 | color: #00008B; 57 | border-bottom: 0 58 | } 59 | 60 | .algolia-autocomplete .algolia-docsearch-suggestion--wrapper { 61 | float: none; 62 | padding-top: 0 63 | } 64 | 65 | .algolia-autocomplete .algolia-docsearch-suggestion--subcategory-column { 66 | float: none; 67 | width: auto; 68 | padding: 0; 69 | text-align: left 70 | } 71 | 72 | .algolia-autocomplete .algolia-docsearch-suggestion--content { 73 | float: none; 74 | width: auto; 75 | padding: 0 76 | } 77 | 78 | .algolia-autocomplete .algolia-docsearch-suggestion--content::before { 79 | display: none 80 | } 81 | 82 | .algolia-autocomplete .ds-suggestion:not(:first-child) .algolia-docsearch-suggestion--category-header { 83 | padding-top: .75rem; 84 | margin-top: .75rem; 85 | border-top: 1px solid rgba(0, 0, 0, .1) 86 | } 87 | 88 | .algolia-autocomplete .ds-suggestion .algolia-docsearch-suggestion--subcategory-column { 89 | display: block; 90 | padding: .1rem 1rem; 91 | margin-bottom: 0.1; 92 | font-size: 1.0em; 93 | font-weight: 400 94 | /* display: none */ 95 | } 96 | 97 | .algolia-autocomplete .algolia-docsearch-suggestion--title { 98 | display: block; 99 | padding: .25rem 1rem; 100 | margin-bottom: 0; 101 | font-size: 0.9em; 102 | font-weight: 400 103 | } 104 | 105 | .algolia-autocomplete .algolia-docsearch-suggestion--text { 106 | padding: 0 1rem .5rem; 107 | margin-top: -.25rem; 108 | font-size: 0.8em; 109 | font-weight: 400; 110 | line-height: 1.25 111 | } 112 | 113 | .algolia-autocomplete .algolia-docsearch-footer { 114 | width: 110px; 115 | height: 20px; 116 | z-index: 3; 117 | margin-top: 10.66667px; 118 | float: right; 119 | font-size: 0; 120 | line-height: 0; 121 | } 122 | 123 | .algolia-autocomplete .algolia-docsearch-footer--logo { 124 | background-image: url("data:image/svg+xml;utf8,"); 125 | background-repeat: no-repeat; 126 | background-position: 50%; 127 | background-size: 100%; 128 | overflow: hidden; 129 | text-indent: -9000px; 130 | width: 100%; 131 | height: 100%; 132 | display: block; 133 | transform: translate(-8px); 134 | } 135 | 136 | .algolia-autocomplete .algolia-docsearch-suggestion--highlight { 137 | color: #FF8C00; 138 | background: rgba(232, 189, 54, 0.1) 139 | } 140 | 141 | 142 | .algolia-autocomplete .algolia-docsearch-suggestion--text .algolia-docsearch-suggestion--highlight { 143 | box-shadow: inset 0 -2px 0 0 rgba(105, 105, 105, .5) 144 | } 145 | 146 | .algolia-autocomplete .ds-suggestion.ds-cursor .algolia-docsearch-suggestion--content { 147 | background-color: rgba(192, 192, 192, .15) 148 | } 149 | -------------------------------------------------------------------------------- /R/statCanR.R: -------------------------------------------------------------------------------- 1 | #' statcanR 2 | #' 3 | #' 4 | #' Easily connect to Statistics Canada's Web Data Service with R. Open economic data (formerly known as CANSIM tables, now identified by Product IDs (PID)) are accessible as a data frame, directly in the user's R environment. 5 | #' 6 | #' The 7 | #' \code{statcan_data()} function has 2 arguments to fulfill to get data: {tableNumber} & {lang}. 8 | #' 9 | #' 10 | #' The tableNumber argument simply refers to the table number of the Statistics Canada data table a user wants to collect, 11 | #' such as '27-10-0014-01' for the Federal expenditures on science and technology, by socio-economic objectives, as an example. 12 | #' 13 | #' 14 | #' To get the table number: \url{https://www150.statcan.gc.ca/n1/en/type/data}. 15 | #' 16 | #' The second argument, lang, refers to the language. As Canada is a bilingual country, Statistics Canada displays all the economic data in both languages. 17 | #' Therefore, users can choose to collect satistics data tables in French or English by setting the lang argument with c('fra', 'eng'). 18 | #' 19 | #' 20 | #' 21 | #' @param tableNumber The table number of the Statistics Canada data table 22 | #' @param lang The language wanted 23 | #' 24 | #' @return The output will be a data table representing the data associated with the chosen table number. 25 | #' @export 26 | #' 27 | #' @import curl 28 | #' @import tibble 29 | #' @import qpdf 30 | #' @importFrom httr http_error 31 | #' @importFrom data.table fread 32 | #' @importFrom data.table setDF 33 | #' 34 | #' @examples 35 | #' #mydata <- statcan_data('27-10-0014-01', 'eng') 36 | #' 37 | 38 | 39 | # Scraping function for statcan 40 | statcan_data <- function(tableNumber, lang) 41 | { 42 | 43 | # identifying the table number 44 | tableNumber <- gsub("-", "", substr(tableNumber, 1, nchar(tableNumber) - 45 | 2)) 46 | 47 | # getting data in English version 48 | if (lang == "eng") 49 | { 50 | # downloading the data file in English version 51 | urlEng <- paste0("https://www150.statcan.gc.ca/n1/en/tbl/csv/", 52 | tableNumber, "-eng.zip") 53 | 54 | download_dir <- file.path(tempdir(), "datasetEng.zip") 55 | 56 | #utils::download.file(urlEng, download_dir, method = "curl") 57 | #data.table::fread(input = urlEng, file = download_dir) 58 | #RCurl::getURL(urlEng, ssl.verifyhost=FALSE, ssl.verifypeer=FALSE) 59 | #curl::curl_download(urlEng, download_dir) 60 | 61 | if (httr::http_error(urlEng)) { # network is down = message (not an error anymore) 62 | message("No Internet connection or incorrect statcan table number or Statistics Canada website under maintenance.") 63 | #return(NULL) 64 | } else { # network is up = proceed to download via curl 65 | message("statcanR: downloading remote table.") 66 | with(options(timeout = max(300, getOption("timeout"))),curl::curl_download(urlEng, download_dir)) 67 | 68 | 69 | # unziping the downloaded data file in English version 70 | unzip_dir <- file.path(paste0(tempdir(), "/")) 71 | utils::unzip(zipfile = download_dir, exdir = unzip_dir) 72 | unlink(download_dir) 73 | 74 | # loading the data file in English version 75 | csv_file <- file.path(paste0(tempdir(), "/", tableNumber, ".csv")) 76 | can_data <- data.table::fread(csv_file) 77 | 78 | # adding to the data.frame or data.table the Official Data Table 79 | # Indicator defined by Statistics Canada and based on metadata file. 80 | can_data$INDICATOR <- as.character(0) 81 | can_data$COORDINATE <- as.character(can_data$COORDINATE) 82 | can_data$INDICATOR <- as.character(readr::read_csv(paste0(tempdir(), 83 | "/", tableNumber, "_MetaData.csv"))[1, 1]) 84 | 85 | if(nchar(can_data[1,1])==9){ 86 | can_data$REF_DATE <- sub(".*/", "", can_data$REF_DATE) 87 | can_data$REF_DATE <- as.Date(paste(can_data$REF_DATE, 3, 31, sep = "-")) 88 | can_data <- tibble::add_column(can_data, REF_PERIOD = "Fiscal year", .before = 2) 89 | } 90 | 91 | else if(nchar(can_data[1,1])==7){ 92 | can_data$REF_DATE <- as.Date(paste(can_data$REF_DATE, 1, sep = "-")) 93 | } 94 | 95 | else if(nchar(can_data[1,1])==4){ 96 | can_data$REF_DATE <- as.Date(paste(can_data$REF_DATE, 1, 1, sep = "-")) 97 | } 98 | 99 | else{ 100 | can_data$REF_DATE <- as.Date(can_data$REF_DATE) 101 | } 102 | 103 | # creating a data frame 104 | data.table::setDF(return(can_data)) 105 | 106 | } # /if - network up or down 107 | 108 | } 109 | 110 | # getting data in French version 111 | if (lang == "fra") 112 | { 113 | # downloading the data file in French version 114 | urlFra <- paste0("https://www150.statcan.gc.ca/n1/fr/tbl/csv/", 115 | tableNumber, "-fra.zip") 116 | 117 | download_dir <- file.path(tempdir(), "datasetFra.zip") 118 | #utils::download.file(urlFra, download_dir, method = "curl") 119 | #data.table::fread(urlFra, download_dir) 120 | #curl::curl_download(urlFra, download_dir) 121 | 122 | if (httr::http_error(urlFra)) { # network is down = message (not an error anymore) 123 | message("No Internet connection or incorrect statcan table number or Statistics Canada website under maintenance.") 124 | return(NULL) 125 | } else { # network is up = proceed to download via curl 126 | message("statcanR: downloading remote table.") 127 | with(options(timeout = max(300, getOption("timeout"))),curl::curl_download(urlFra, download_dir)) 128 | 129 | 130 | # unzipping the downloaded data file in French version 131 | unzip_dir <- file.path(paste0(tempdir(), "/")) 132 | utils::unzip(zipfile = download_dir, exdir = unzip_dir) 133 | unlink(download_dir) 134 | 135 | # loading the data file in French version 136 | csv_file <- file.path(paste0(tempdir(), "/", tableNumber, ".csv")) 137 | can_data <- data.table::fread(csv_file) 138 | 139 | # adding to the data.frame or data.table the Official Data Table 140 | # Indicator defined by Statitics Canada and based on metadata file. 141 | can_data$INDICATOR <- as.character(0) 142 | can_data$COORDINATE <- as.character(can_data$COORDINATE) 143 | can_data$INDICATOR <- as.character(readr::read_delim(paste0(tempdir(), 144 | "/", tableNumber, "_MetaData.csv"), delim = ";", escape_double = FALSE, trim_ws = TRUE)[1, 1]) 145 | 146 | can_data[,1] <- "REF_DATE" 147 | 148 | if(nchar(can_data[1,1])==9){ 149 | can_data$REF_DATE <- sub(".*/", "", can_data$REF_DATE) 150 | can_data$REF_DATE <- as.Date(paste(can_data$REF_DATE, 3, 31, sep = "-")) 151 | can_data <- tibble::add_column(can_data, REF_PERIOD = "Fiscal year", .before = 2) 152 | } 153 | 154 | else if(nchar(can_data[1,1])==7){ 155 | can_data$REF_DATE <- as.Date(paste(can_data$REF_DATE, 1, sep = "-")) 156 | } 157 | 158 | else if(nchar(can_data[1,1])==4){ 159 | can_data$REF_DATE <- as.Date(paste(can_data$REF_DATE, 1, 1, sep = "-")) 160 | } 161 | 162 | else{ 163 | can_data$REF_DATE <- as.Date(can_data$REF_DATE) 164 | } 165 | 166 | # creating a data frame 167 | data.table::setDF(return(can_data)) 168 | } # /if - network up or down 169 | 170 | } 171 | 172 | 173 | # removing the temp folder and creating a data frame 174 | unlink(tempdir()) 175 | 176 | } 177 | 178 | #' statcanR download data function 179 | #' 180 | #' @param tableNumber The table number of the Statistics Canada data table 181 | #' @param lang The language wanted 182 | #' 183 | #' @return The output will be a data table and csv file representing the data associated with the chosen table number. 184 | #' @export 185 | #' 186 | #' 187 | #' @import curl 188 | #' @import tibble 189 | #' @importFrom httr http_error 190 | #' @importFrom data.table fread 191 | #' @importFrom data.table setDF 192 | #' 193 | #' @examples 194 | #' mydata <- statcan_data('27-10-0014-01', 'eng') 195 | 196 | # Download function for statcan 197 | statcan_download_data <- function(tableNumber, lang) 198 | { 199 | 200 | # identifying the table number 201 | tableNumber <- gsub("-", "", substr(tableNumber, 1, nchar(tableNumber) - 202 | 2)) 203 | 204 | # getting data in English version 205 | if (lang == "eng") 206 | { 207 | # downloading the data file in English version 208 | urlEng <- paste0("https://www150.statcan.gc.ca/n1/en/tbl/csv/", 209 | tableNumber, "-eng.zip") 210 | 211 | download_dir <- file.path(tempdir(), "datasetEng.zip") 212 | #utils::download.file(urlEng, download_dir, method = "curl") 213 | #data.table::fread(input = urlEng, file = download_dir) 214 | #RCurl::getURL(urlEng, ssl.verifyhost=FALSE, ssl.verifypeer=FALSE) 215 | #curl::curl_download(urlEng, download_dir) 216 | 217 | if (httr::http_error(urlEng)) { # network is down = message (not an error anymore) 218 | message("No Internet connection or incorrect statcan table number or Statistics Canada website under maintenance.") 219 | #return(NULL) 220 | } else { # network is up = proceed to download via curl 221 | message("statcanR: downloading remote table.") 222 | with(options(timeout = max(300, getOption("timeout"))),curl::curl_download(urlEng, download_dir)) 223 | 224 | # unziping the downloaded data file in English version 225 | unzip_dir <- file.path(paste0(tempdir(), "/")) 226 | utils::unzip(zipfile = download_dir, exdir = unzip_dir) 227 | unlink(download_dir) 228 | 229 | # loading the data file in English version 230 | csv_file <- file.path(paste0(tempdir(), "/", tableNumber, ".csv")) 231 | can_data <- data.table::fread(csv_file) 232 | 233 | # adding to the data.frame or data.table the Official Data Table 234 | # Indicator defined by Statistics Canada and based on metadata file. 235 | can_data$INDICATOR <- as.character(0) 236 | can_data$COORDINATE <- as.character(can_data$COORDINATE) 237 | can_data$INDICATOR <- as.character(readr::read_csv(paste0(tempdir(), 238 | "/", tableNumber, "_MetaData.csv"))[1, 1]) 239 | 240 | if(nchar(can_data[1,1])==9){ 241 | can_data$REF_DATE <- sub(".*/", "", can_data$REF_DATE) 242 | can_data$REF_DATE <- as.Date(paste(can_data$REF_DATE, 3, 31, sep = "-")) 243 | can_data <- tibble::add_column(can_data, REF_PERIOD = "Fiscal year", .before = 2) 244 | } 245 | 246 | else if(nchar(can_data[1,1])==7){ 247 | can_data$REF_DATE <- as.Date(paste(can_data$REF_DATE, 1, sep = "-")) 248 | } 249 | 250 | else if(nchar(can_data[1,1])==4){ 251 | can_data$REF_DATE <- as.Date(paste(can_data$REF_DATE, 1, 1, sep = "-")) 252 | } 253 | 254 | else{ 255 | can_data$REF_DATE <- as.Date(can_data$REF_DATE) 256 | } 257 | # creating a data frame 258 | data.table::setDF(return(can_data)) 259 | readr::write_csv(can_data, paste0("./statcan_",tableNumber,"_", lang,".csv")) 260 | 261 | } # /if - network up or down 262 | 263 | } 264 | 265 | # getting data in French version 266 | if (lang == "fra") 267 | { 268 | # downloading the data file in French version 269 | urlFra <- paste0("https://www150.statcan.gc.ca/n1/fr/tbl/csv/", 270 | tableNumber, "-fra.zip") 271 | 272 | download_dir <- file.path(tempdir(), "datasetFra.zip") 273 | #utils::download.file(urlFra, download_dir, method = "curl") 274 | #data.table::fread(urlFra, download_dir) 275 | #curl::curl_download(urlFra, download_dir) 276 | 277 | if (httr::http_error(urlFra)) { # network is down = message (not an error anymore) 278 | message("No Internet connection or incorrect statcan table number or Statistics Canada website under maintenance.") 279 | return(NULL) 280 | } else { # network is up = proceed to download via curl 281 | message("statcanR: downloading remote table.") 282 | with(options(timeout = max(300, getOption("timeout"))),curl::curl_download(urlFra, download_dir)) 283 | 284 | 285 | 286 | # unzipping the downloaded data file in French version 287 | unzip_dir <- file.path(paste0(tempdir(), "/")) 288 | utils::unzip(zipfile = download_dir, exdir = unzip_dir) 289 | unlink(download_dir) 290 | 291 | # loading the data file in French version 292 | csv_file <- file.path(paste0(tempdir(), "/", tableNumber, ".csv")) 293 | can_data <- data.table::fread(csv_file) 294 | 295 | # adding to the data.frame or data.table the Official Data Table 296 | # Indicator defined by Statistics Canada and based on metadata file. 297 | can_data$INDICATOR <- as.character(0) 298 | can_data$COORDINATE <- as.character(can_data$COORDINATE) 299 | can_data$INDICATOR <- as.character(readr::read_delim(paste0(tempdir(), 300 | "/", tableNumber, "_MetaData.csv"), delim = ";", escape_double = FALSE, trim_ws = TRUE)[1, 1]) 301 | 302 | can_data[,1] <- "REF_DATE" 303 | 304 | if(nchar(can_data[1,1])==9){ 305 | can_data$REF_DATE <- sub(".*/", "", can_data$REF_DATE) 306 | can_data$REF_DATE <- as.Date(paste(can_data$REF_DATE, 3, 31, sep = "-")) 307 | can_data <- tibble::add_column(can_data, REF_PERIOD = "Fiscal year", .before = 2) 308 | } 309 | 310 | else if(nchar(can_data[1,1])==7){ 311 | can_data$REF_DATE <- as.Date(paste(can_data$REF_DATE, 1, sep = "-")) 312 | } 313 | 314 | else if(nchar(can_data[1,1])==4){ 315 | can_data$REF_DATE <- as.Date(paste(can_data$REF_DATE, 1, 1, sep = "-")) 316 | } 317 | 318 | else{ 319 | can_data$REF_DATE <- as.Date(can_data$REF_DATE) 320 | } 321 | # creating a data frame 322 | data.table::setDF(return(can_data)) 323 | 324 | readr::write_csv(can_data, paste0("./statcan_",tableNumber,"_", lang,".csv")) 325 | } # /if - network up or down 326 | } 327 | 328 | # removing the temp folder and creating a data frame 329 | unlink(tempdir()) 330 | } -------------------------------------------------------------------------------- /docs/articles/statCanR.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | statCanR • statcanR 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 20 | 21 | 22 | 23 | 24 |
    25 |
    77 | 78 | 79 | 80 | 81 |
    82 |
    83 | 93 | 94 | 95 | 96 | 98 |
    99 |

    Overview 100 |

    101 |

    statcanR provides the R user with a consistent process to identify 102 | and collect data from Statistics Canada’s data portal. It allows users 103 | to search for and access all of Statistics Canada’ open economic data 104 | (formerly known as CANSIM tables) now identified by product IDs (PID) by 105 | the new Statistics Canada’s Web Data Service: https://www150.statcan.gc.ca/n1/en/type/data.

    106 |
    107 |
    108 |

    Quick start 109 |

    110 |

    First, install statcanR:

    111 |
    112 | devtools::install_github("warint/statcanR")
    113 |

    Next, call statcanR to make sure everything is installed 114 | correctly.

    115 | 117 |
    118 |
    119 |

    Practical usage 120 |

    121 |

    This section presents an example of how to use the statcanR R package 122 | and its functions: statcan_search() and statcan_data().

    123 |

    The following example is provided to illustrate how to use these 124 | functions. It consists of collecting some descriptive statistics about 125 | the Canadian labour force at the federal, provincial and industrial 126 | levels, on a monthly basis.

    127 |

    To identify a relevant table, the statcan_search() function can be 128 | used by using a keyword or set of keywords, depending on the language 129 | the user wishes to search in (between English and French). Below is an 130 | example that reveals the data tables we could be interested in:

    131 |
    132 | # Identify with statcan_search() function
    133 | statcan_search(c("federal","expenditures"),"eng")
    134 |

    Notice that for each corresponding table, the unique table number 135 | identifier is also presented. Let’s focus on the first table out of the 136 | two that appear, which contains data on Federal expenditures on science 137 | and technology, by socio-economic objectives. Once this table number is 138 | identified (‘27-10-0014-01’), the statcan_data() function is easy to use 139 | in order to collect the data, as following:

    140 |
    141 | # Get data with statcan_data function
    142 | mydata <- statcan_download_data("27-10-0014-01", "eng")
    143 |

    Should you want the same data in French, just replace the argument at 144 | the end of the function with “fra”.

    145 |
    146 |

    Code architecture 147 |

    148 |

    This section describes the code architecture of the statcanR 149 | package.

    150 |

    The statcan_search() function has 2 arguments:

    151 |
      152 |
    1. keywords
    2. 153 |
    3. lang
    4. 154 |
    155 |

    The ‘keywords’ argument is useful for identifying what kind of open 156 | economic data Statistics Canada has available for users. It can take as 157 | inputs either a single word (i.e., statcan_search(“expenditures”)) or a 158 | vector of multiple keywords (such as: 159 | statcan_search(c(“expenditures”,“federal”,“objectives”))).

    160 |

    The second argument, ‘lang’, refers to the language. As Canada is a 161 | bilingual country, Statistics Canada displays all the economic data in 162 | both languages. Therefore, users can see what data tables are available 163 | in French or English by setting the lang argument with c(“fra”, 164 | “eng”).

    165 |

    For all data tables that contain these words in either their title or 166 | description, the resulting output will include four pieces of 167 | information: The name of the data table, its unique table number 168 | identifier, the description, and the release date. In details, the 169 | statcan_download_data() function has 2 arguments:

    170 |
      171 |
    1. tableNumber
    2. 172 |
    3. lang
    4. 173 |
    174 |

    The ‘tableNumber’ argument simply refers to the table number of the 175 | Statistics Canada data table a user wants to collect, such as 176 | ‘27-10-0014-01’ for the Federal expenditures on science and technology, 177 | by socio-economic objectives, as an example.

    178 |

    Just as in the statcan_search() command, ‘lang’, refers to the 179 | language, and can be set to “eng” for English or “fra” for French. 180 | Therefore, users can choose to collect satistics data tables in French 181 | or English by setting the lang argument with c(“fra”, “eng”).

    182 |

    The code architecture of the statcan_download_data() function is as 183 | follows. The first step if to clean the table number in order to align 184 | it with the official typology of Statistics Canada’s Web Data Service. 185 | The second step is to create a temporary folder where all the data 186 | wrangling operations are performed. The third step is to check and 187 | select the correct language. The fourth step is to define the right URL 188 | where the actual data table is stored and then to download the .Zip 189 | container. The fifth step is to unzip the previously downloaded .Zip 190 | file to extract the data and metadata from the .csv files. The final 191 | step is to load the statistics data into a data frame called ‘data’ and 192 | to add the official table indicator name in the new ‘INDICATOR’ 193 | column.

    194 |

    To be more precise about the functions, below is some further code 195 | description:

    196 |
    197 | 199 |
      200 |
    • keyword_regex <- paste0("(", paste(keywords, collapse = "|"), ")", collapse = ".*"): 201 | The first step is to paste (either individually or in vector format) the 202 | keywords the user is interested in

    • 203 |
    • matches <- apply(statcan_data, 1, function(row) { 204 | all(sapply(keywords, function(x) { 205 | grepl(x, paste(as.character(row), collapse = " ")) 206 | })) }): Next, the matching relies on the 207 | sapply function, which is applied to any character string in a row of a 208 | given observation. Therefore, the “keyword” could be found in the title 209 | column or the description column (technically, it could even be in the 210 | “release date” or “id” columns).

    • 211 |
    • filtered_data <- statcan_data[matches, ] The 212 | third step takes only the data where matches were found.

    • 213 |
    • datatable(filtered_data, options = list(pageLength = 10)) 214 | Finally, the datatable command presents the filtered data in a clean 215 | table.

    • 216 |
    217 |
    218 |
    219 |

    statcan_download_data() 220 |

    221 |
      222 |
    • tableNumber <- gsub("-", "", substr(tableNumber, 1, nchar(tableNumber)-2)): 223 | The first step is to clean the table number provided by the user in 224 | order to collect the overall data table related to the specific 225 | indicator the user is interested in. In fact, each indicator is an 226 | excerpt of the overall table. In addition, following the new Statistics 227 | Canada’s Web Data Service, the URL typology defined by REST API is 228 | stored in csv files by table numbers without a ‘-’. Also, the last 2 229 | digits after the last ‘-’ refer to the specific excerpt of the original 230 | table. Therefore, following the Statistics Canada Web Data Service’s 231 | typology, the function first removes the ‘-’ and the last 2 digits from 232 | the user’s selection.

    • 233 |
    • if(lang == "eng") | if(lang == "fra"): 234 | The second step is the ‘if statement’ to get the data in the correct 235 | language.

    • 236 |
    • urlFra <- paste0("https://www150.statcan.gc.ca/n1/fr/tbl/csv/", tableNumber, "-fra.zip"): 237 | The third step is to create the correct url in order to download the 238 | respective .Zip file from the Statistics Canada Web Data 239 | Service.

    • 240 |
    • download(urlFra, download_dir, mode = "wb"): The 241 | fourth step is a simple downloading function that extracts .Zip file and 242 | download it into a temporary folder.

    • 243 |
    • unzip(zipfile = download_dir, exdir = unzip_dir): 244 | The fifth step consists in unzipping the .Zip file. The unzipping 245 | process gives access to two different .csv files, such as the overall 246 | data table and the metadata table.

    • 247 |
    • data.table::fread(csv_file): The sixth step consists 248 | in loading the data table into a unique data frame. The fread() function 249 | from the data.table package is used for its higher performance.

    • 250 |
    • data$INDICATOR <- as.character(0) and 251 | data$INDICATOR <- as.character(read.csv(paste0(path,"/temp/", tableNumber, "_MetaData.csv"))[1,1]): 252 | The seventh step of the statcan_data() function consists in adding the 253 | name of the table from the metadata table.

    • 254 |
    • unlink(tempdir()): The eighth step deletes the 255 | temporary folder used to download, unzip, extract and load the 256 | data.

    • 257 |
    • return(Data): Finally, the last step of the 258 | statcan_data() function allows to return the value into the user’s 259 | environment.

    • 260 |
    261 |
    262 |
    263 |
    264 |
    265 | 266 | 271 | 272 |
    273 | 274 | 275 | 276 | 287 |
    288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | --------------------------------------------------------------------------------