├── .Rbuildignore
├── .github
├── .gitignore
├── CONTRIBUTING.md
├── FUNDING.yml
└── workflows
│ ├── R-CMD-check.yaml
│ └── test-coverage.yaml
├── .gitignore
├── CODE_OF_CONDUCT.md
├── CRAN-SUBMISSION
├── DESCRIPTION
├── LICENSE
├── NAMESPACE
├── NEWS.md
├── R
├── ots_cache.R
├── ots_create_tidy_data.R
├── ots_gdp_deflator_adjustment.R
├── ots_license_message.R
├── ots_read_from_api.R
├── ots_strings_processing.R
└── tradestatistics-package.R
├── README.Rmd
├── README.md
├── _pkgdown.yml
├── codecov.yml
├── codemeta.json
├── cran-comments.md
├── data-raw
├── ots_commodities.json
├── ots_commodities_short.json
├── ots_countries.json
├── ots_countries_colors.json
├── ots_sections.json
├── ots_sections_colors.json
└── ots_tables.csv
├── data
├── ots_commodities.rda
├── ots_commodities_short.rda
├── ots_countries.rda
├── ots_countries_colors.rda
├── ots_gdp_deflator.rda
├── ots_sections.rda
├── ots_sections_colors.rda
└── ots_tables.rda
├── dev
├── config_attachment.yaml
└── creating-datasets.R
├── inst
└── references.bib
├── man
├── figures
│ └── hexicon.svg
├── ots_cache.Rd
├── ots_commodities.Rd
├── ots_commodities_short.Rd
├── ots_commodity_code.Rd
├── ots_countries.Rd
├── ots_countries_colors.Rd
├── ots_country_code.Rd
├── ots_create_tidy_data.Rd
├── ots_create_tidy_data_memoised.Rd
├── ots_create_tidy_data_unmemoised.Rd
├── ots_gdp_deflator.Rd
├── ots_gdp_deflator_adjustment.Rd
├── ots_read_from_api.Rd
├── ots_sections.Rd
├── ots_sections_colors.Rd
├── ots_tables.Rd
└── tradestatistics-package.Rd
├── paper
├── chicago.csl
├── paper.pdf
└── paper.rmd
├── svg
├── data-diagram.svg
└── hexicon.svg
├── tests
├── fixtures
│ └── vcr_cassettes
│ │ ├── chl_all_2002_yrp.yml
│ │ ├── chl_arg_2002_yr.yml
│ │ ├── chl_arg_2002_yr_apple.yml
│ │ ├── chl_arg_2002_yrp.yml
│ │ ├── chl_arg_2002_yrpc.yml
│ │ ├── chl_arg_2002_yrpc_cache.yml
│ │ ├── chl_arg_2002_yrpc_fish.yml
│ │ ├── chl_arg_2002_yrpc_wheat.yml
│ │ ├── chl_arg_2004_yr.yml
│ │ ├── chl_arg_2004_yrpc.yml
│ │ └── chl_myt_2002_yrp.yml
├── testthat.R
└── testthat
│ ├── helper-tradestatistics.R
│ ├── test-ots_country_code.R
│ ├── test-ots_create_tidy_data.R
│ ├── test-ots_inflation_adjustment.R
│ └── test-ots_strings_processing.R
├── tradestatistics.Rproj
└── vignettes
├── basic-usage.R
├── basic-usage.Rmd
└── basic-usage.html
/.Rbuildignore:
--------------------------------------------------------------------------------
1 | ^codemeta\.json$
2 | ^.*\.Rproj$
3 | ^\.Rproj\.user$
4 | _pkgdown.yml
5 | .travis.yml
6 | appveyor.yml
7 | README.md
8 | README.Rmd
9 | docs
10 | ^codecov\.yml$
11 | ^CODE_OF_CONDUCT\.md$
12 | data-raw
13 | LICENSE
14 | svg
15 | vignettes/basic-usage_cache/
16 | ^\.github$
17 | dev
18 | ^CRAN-SUBMISSION$
19 | paper
20 | ^cran-comments\.md$
21 |
--------------------------------------------------------------------------------
/.github/.gitignore:
--------------------------------------------------------------------------------
1 | *.html
2 |
--------------------------------------------------------------------------------
/.github/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to tradestatistics
2 |
3 | This outlines how to propose a change to tradestatistics. For more detailed
4 | info about contributing to this, and other tidyverse packages, please see the
5 | [**development contributing guide**](https://rstd.io/tidy-contrib).
6 |
7 | ### Fixing typos
8 |
9 | Small typos or grammatical errors in documentation may be edited directly using
10 | the GitHub web interface, so long as the changes are made in the _source_ file.
11 |
12 | * YES: you edit a roxygen comment in a `.R` file below `R/`.
13 | * NO: you edit an `.Rd` file below `man/`.
14 |
15 | ### Prerequisites
16 |
17 | Before you make a substantial pull request, you should always file an issue and
18 | make sure someone from the team agrees that it’s a problem. If you’ve found a
19 | bug, create an associated issue and illustrate the bug with a minimal
20 | [reprex](https://www.tidyverse.org/help/#reprex).
21 |
22 | ### Pull request process
23 |
24 | * We recommend that you create a Git branch for each pull request (PR).
25 | * Look at the Travis and AppVeyor build status before and after making changes.
26 | The `README` should contain badges for any continuous integration services used
27 | by the package.
28 | * New code should follow the tidyverse [style guide](https://style.tidyverse.org).
29 | You can use the [styler](https://CRAN.R-project.org/package=styler) package to
30 | apply these styles, but please don't restyle code that has nothing to do with
31 | your PR.
32 | * We use [roxygen2](https://cran.r-project.org/package=roxygen2), with
33 | [Markdown syntax](https://cran.r-project.org/web/packages/roxygen2/vignettes/markdown.html),
34 | for documentation.
35 | * We use [testthat](https://cran.r-project.org/package=testthat). Contributions
36 | with test cases included are easier to accept.
37 | * For user-facing changes, add a bullet to the top of `NEWS.md` below the
38 | current development version header describing the changes made followed by your
39 | GitHub username, and links to relevant issue(s)/PR(s).
40 |
41 | ### Code of Conduct
42 |
43 | Please note that the tradestatistics project is released with a
44 | [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By contributing to this
45 | project you agree to abide by its terms.
46 |
47 | ### See tidyverse [development contributing guide](https://rstd.io/tidy-contrib)
48 | for further details.
49 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | custom: ['https://www.buymeacoffee.com/pacha']
4 |
--------------------------------------------------------------------------------
/.github/workflows/R-CMD-check.yaml:
--------------------------------------------------------------------------------
1 | # For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag.
2 | # https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions
3 | on:
4 | push:
5 | branches:
6 | - main
7 | - master
8 | pull_request:
9 | branches:
10 | - main
11 | - master
12 |
13 | name: R-CMD-check
14 |
15 | jobs:
16 | R-CMD-check:
17 | runs-on: ${{ matrix.config.os }}
18 |
19 | name: ${{ matrix.config.os }} (${{ matrix.config.r }})
20 |
21 | strategy:
22 | fail-fast: false
23 | matrix:
24 | config:
25 | - {os: windows-latest, r: 'release'}
26 | - {os: macOS-latest, r: 'release'}
27 | - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
28 |
29 | env:
30 | R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
31 | RSPM: ${{ matrix.config.rspm }}
32 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
33 |
34 | steps:
35 | - uses: actions/checkout@v2
36 |
37 | - uses: r-lib/actions/setup-r@v2
38 | with:
39 | r-version: ${{ matrix.config.r }}
40 |
41 | - uses: r-lib/actions/setup-pandoc@v1
42 |
43 | - name: Query dependencies
44 | run: |
45 | install.packages('remotes')
46 | saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
47 | writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
48 | shell: Rscript {0}
49 |
50 | - name: Restore R package cache
51 | uses: actions/cache@v2
52 | with:
53 | path: ${{ env.R_LIBS_USER }}
54 | key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
55 | restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
56 |
57 | - name: Install system dependencies
58 | if: runner.os == 'Linux'
59 | run: |
60 | while read -r cmd
61 | do
62 | eval sudo $cmd
63 | done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')
64 |
65 | - name: Install dependencies
66 | run: |
67 | remotes::install_deps(dependencies = TRUE)
68 | remotes::install_cran("rcmdcheck")
69 | shell: Rscript {0}
70 |
71 | - name: Check
72 | env:
73 | _R_CHECK_CRAN_INCOMING_REMOTE_: false
74 | run: |
75 | options(crayon.enabled = TRUE)
76 | rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
77 | shell: Rscript {0}
78 |
79 | - name: Upload check results
80 | if: failure()
81 | uses: actions/upload-artifact@main
82 | with:
83 | name: ${{ runner.os }}-r${{ matrix.config.r }}-results
84 | path: check
85 |
--------------------------------------------------------------------------------
/.github/workflows/test-coverage.yaml:
--------------------------------------------------------------------------------
1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
3 | on:
4 | push:
5 | branches: [main, master]
6 | pull_request:
7 | branches: [main, master]
8 |
9 | name: test-coverage
10 |
11 | jobs:
12 | test-coverage:
13 | runs-on: ubuntu-latest
14 | env:
15 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
16 |
17 | steps:
18 | - uses: actions/checkout@v2
19 |
20 | - uses: r-lib/actions/setup-r@v2
21 | with:
22 | use-public-rspm: true
23 |
24 | - uses: r-lib/actions/setup-r-dependencies@v2
25 | with:
26 | extra-packages: any::covr
27 | needs: coverage
28 |
29 | - name: Test coverage
30 | run: covr::codecov(quiet = FALSE)
31 | shell: Rscript {0}
32 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .Rproj.user
2 | .Renviron
3 | .Rhistory
4 | .Ruserdata
5 | .Rapp.history
6 | .build.timestamp
7 | .DS_Store
8 | __MACOSX
9 | *.tex
10 | *.tar.gz
11 | README.html
12 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Code of Conduct
2 |
3 | As contributors and maintainers of this project, we pledge to respect all people who
4 | contribute through reporting issues, posting feature requests, updating documentation,
5 | submitting pull requests or patches, and other activities.
6 |
7 | We are committed to making participation in this project a harassment-free experience for
8 | everyone, regardless of level of experience, gender, gender identity and expression,
9 | sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
10 |
11 | Examples of unacceptable behavior by participants include the use of sexual language or
12 | imagery, derogatory comments or personal attacks, trolling, public or private harassment,
13 | insults, or other unprofessional conduct.
14 |
15 | Project maintainers have the right and responsibility to remove, edit, or reject comments,
16 | commits, code, wiki edits, issues, and other contributions that are not aligned to this
17 | Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed
18 | from the project team.
19 |
20 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by
21 | opening an issue or contacting one or more of the project maintainers.
22 |
23 | This Code of Conduct is adapted from the Contributor Covenant
24 | (http://contributor-covenant.org), version 1.0.0, available at
25 | http://contributor-covenant.org/version/1/0/0/
26 |
--------------------------------------------------------------------------------
/CRAN-SUBMISSION:
--------------------------------------------------------------------------------
1 | Version: 5.0.0
2 | Date: 2024-08-22 20:59:19 UTC
3 | SHA: 504254a812eeb539fd0ca6e84b83e3bd3996d96c
4 |
--------------------------------------------------------------------------------
/DESCRIPTION:
--------------------------------------------------------------------------------
1 | Type: Package
2 | Package: tradestatistics
3 | Title: Open Trade Statistics API Wrapper and Utility Program
4 | Version: 5.0.0
5 | Authors@R: c(
6 | person("Mauricio", "Vargas", , "mavargas11@uc.cl", role = c("aut", "cre", "cph"),
7 | comment = c(ORCID = "0000-0003-1017-7574")),
8 | person("Joshua", "Kunst", role = "ctb",
9 | comment = "contributed to different parts of the pre-release code"),
10 | person("Alexey", "Kravchenko", role = "ctb",
11 | comment = "reviewed 2021 version of the API"),
12 | person("Emma", "Mendelsohn", role = "ctb",
13 | comment = "updated the functions to take available years from the API instead of hardcoded values"),
14 | person("Daniela", "de los Santos", role = "ctb",
15 | comment = "proposed improvements to default parameters"),
16 | person("Emily", "Riederer", role = "rev",
17 | comment = "reviewed the package for rOpenSci, see https://github.com/ropensci/onboarding/issues/274"),
18 | person("Mark", "Padgham", role = "rev",
19 | comment = "reviewed the package for rOpenSci, see https://github.com/ropensci/onboarding/issues/274"),
20 | person("Amanda", "Dobbyn", role = "rev",
21 | comment = "reviewed a previous package that evolved into the current package for rOpenSci, see https://github.com/ropensci/onboarding/issues/217"),
22 | person("Jorge", "Cimentada", role = "rev",
23 | comment = "reviewed a previous package that evolved into the current package for rOpenSci, see https://github.com/ropensci/onboarding/issues/217"),
24 | person(, "UN Comtrade", role = "dtc"),
25 | person(, "The World Bank", role = "dtc")
26 | )
27 | Description: Access 'Open Trade Statistics' API from R to download
28 | international trade data.
29 | License: Apache License (>= 2)
30 | URL: https://docs.ropensci.org/tradestatistics/
31 | BugReports: https://github.com/ropensci/tradestatistics/issues/
32 | Depends:
33 | R (>= 2.10)
34 | Imports:
35 | crul,
36 | data.table,
37 | digest,
38 | jsonlite,
39 | memoise,
40 | utils
41 | Suggests:
42 | covr,
43 | knitr,
44 | rmarkdown,
45 | testthat (>= 2.1.0),
46 | tibble,
47 | vcr
48 | VignetteBuilder:
49 | knitr
50 | Encoding: UTF-8
51 | LazyData: TRUE
52 | RoxygenNote: 7.3.1
53 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/NAMESPACE:
--------------------------------------------------------------------------------
1 | # Generated by roxygen2: do not edit by hand
2 |
3 | export(ots_commodity_code)
4 | export(ots_country_code)
5 | export(ots_create_tidy_data)
6 | export(ots_gdp_deflator_adjustment)
7 | importFrom(crul,HttpClient)
8 | importFrom(data.table,`:=`)
9 | importFrom(data.table,fread)
10 | importFrom(data.table,fwrite)
11 | importFrom(data.table,last)
12 | importFrom(data.table,rbindlist)
13 | importFrom(data.table,setnames)
14 | importFrom(digest,digest)
15 | importFrom(jsonlite,fromJSON)
16 | importFrom(memoise,forget)
17 | importFrom(memoise,memoise)
18 | importFrom(utils,read.csv)
19 |
--------------------------------------------------------------------------------
/NEWS.md:
--------------------------------------------------------------------------------
1 | # version 5.0
2 |
3 | * Expands data to 1980-2021 (previously it covered 2002-2020).
4 | * All the data was converted to HS12 from the original SITC2, HS92, HS02, HS07
5 | and HS12 sources.
6 |
7 | # version 4.5
8 |
9 | * Reflects changes in the API and therefore reads JSON data.
10 | * Continues to use data.table for the internals and tibble to display the
11 | results nicely.
12 | * Future versions will only use tibble but that would require effort.
13 |
14 | # version 4.2
15 |
16 | Updates
17 | * Adds dyadic distances table (`ots_distances`) for gravity modelling
18 |
19 | Breaking changes
20 | * The API now returns Parquet files instead of JSON for all the cases (except
21 | for available years and tables)
22 | * All the tests were adapted to reflect changes in the DB (i.e., the test
23 | "multiple country match = error"
24 | no longer returns an error because there are no two codes for Germany in
25 | 2002-2020)
26 | * The command use_localhost was removed because the Shiny app now connects
27 | directly to PostgreSQL (i.e., this saves resources)
28 | * The column EU-28 member was removed from the countries table (i.e., avoid UK
29 | confusion after Brexit)
30 |
31 | # version 4.1
32 |
33 | Updates
34 | * Uses GDP deflator to convert dollars from one year to another (previously
35 | it used reported inflation)
36 | Breaking changes
37 | * New port for local instance (8080 -> 4949)
38 |
39 | # version 4.0
40 |
41 | Updates
42 | * Provides ysrpc table to visualize products, replacing yc tables.
43 | * The new default option is to download imputed data, as there is no
44 | direct API access to raw data.
45 | * A new method to correct import/exports mismatches was applied and the datasets
46 | now start from 1980 until I test enough the model results for older years.
47 | * Drops yr-sections and yr-groups tables
48 | * Drops 'group' columns in the final data (and replaces it for 'section'
49 | columns)
50 | * Allows to access both raw and imputed data from the API
51 | * Allows to search for special codes in the API (i.e., e-490 and other codes)
52 | * All these changes have resulted in large speedups with both data downloading
53 | and the Open Trade Statistics dashboard
54 |
55 | Breaking changes
56 | * Most of the tables in the API were renamed, as now I made available an
57 | imputation method to remove transportation costs (and correct mismatching
58 | flows)
59 |
60 | # version 3.0.3
61 |
62 | Minor fixes
63 | * Adds attributes to parquet tables (i.e., it now does the joins to
64 | add product name, section color, etc.)
65 |
66 | Updates
67 | * Uses "_name" instead of "_fullname_english" in final tables colnames
68 |
69 | # version 3.0.2
70 |
71 | Updates
72 | * Allows to obtain tables in Parquet format from the API, giving a speed-up
73 | of ~50% for the final user.
74 | * Uses tibble instead of DT to produce lighter vignettes
75 |
76 | # version 3.0.1
77 |
78 | Updates
79 | * Adds section colors data for visualization, this is taken from the palette
80 | used in shiny.tradestatistics.io
81 |
82 | # Version 3.0
83 |
84 | Updates
85 | * Removes all references to tables using communities or short names
86 | (both unofficial), reflecting changes in the API
87 | * The functionality remains the same, but now the end user functions don't
88 | add a 21-colors palette to the data (i.e. see the data section)
89 |
90 | Data
91 |
92 | * Switches from HS92 to HS12 to reflect product changes with less aggregation
93 | * Drops any data from Harvard (communities and short product names) as these
94 | depend on using HS92 4 digits, therefore the color palettes were removed as
95 | these depended on the communities table
96 | * The inflation data was trimmed to a window since the year 2000
97 | * The commodities data now contains information for +5000 products instead of
98 | +1200 as the aggregation level changed in the API
99 | * Adds RTAs and MFN tariffs for gravity modelling
100 |
101 | # Version 2.0
102 |
103 | Updates
104 |
105 | * Uses ISO codes as is (affects Aruba, Roumania, Timor-Leste, Antarctica,
106 | Saint Barthelemy, Curacao, Sint Maarten and South Sudan)
107 |
108 | # Version 1.0
109 |
110 | Updates
111 |
112 | * Reflects API changes with less aggregated data
113 | * Follows UN COMTRADE notation (i.e. commodity instead of product)
114 | * Does not impute data before hand, which is better for most of gravity models
115 | use cases
116 | * Provides the data exactly as in the API, returning commodity level data to
117 | allow users to do their own aggregation
118 | * Does not drop reference year with inflation adjustment
119 | (https://github.com/ropensci/tradestatistics/issues/38)
120 | * Takes max and min available years from the API instead of hardcoded values
121 | (https://github.com/ropensci/tradestatistics/pull/39)
122 |
123 | # Version 0.4.0
124 |
125 | Updates
126 |
127 | * Includes `yrpc-ga`, `yrpc-sa`, `yrc-ga` and `yr-sa` tables reflecting API
128 | updates
129 | * Simplifies end-user functions a bit (i.e. removes `include_groups` option)
130 | * Optimizes the code a bit, specially at the joins with tables in the package
131 | * Fixes codes duplication when both product and group/community match for a
132 | search
133 | * Includes both official and shortened section names
134 |
135 | # Version 0.3.1
136 |
137 | Updates
138 |
139 | * Removes `yrp_short` option reflecting last DB changes
140 |
141 | # Version 0.3
142 |
143 | Updates
144 |
145 | * Much improved coverage to detect almost any possible error
146 | * Fixes case in inflation adjustment when year = reference year
147 |
148 | # Version 0.2.8
149 |
150 | Updates
151 |
152 | * Adds caching (in memory or on disk) option (partial contributions from
153 | @eliocamp)
154 | * Includes forwards and backwards testing for inflation adjustment
155 | * Testing for in memory caching
156 |
157 | # Version 0.2.7
158 |
159 | Updates
160 |
161 | * Adds feedback provided by @danidlsa
162 | * Now ots_create_tidy_data() has both reporter and partner set to "all" by
163 | default
164 |
165 | # Version 0.2.5
166 |
167 | Updates
168 |
169 | * Added dependency on R >= 3.5.0 because serialized objects in serialize/load
170 | version 3 cannot be read in older versions of R
171 | * Minimal changes in `ots_create_tidy_data()` to allow multiple countries as
172 | arguments, in line with API changes from September 2019
173 |
174 | # Version 0.2.4
175 |
176 | Updates
177 |
178 | * Removes `product_code_length`
179 | * The API was updated with simplified parameters and 2018 data
180 |
181 | # Version 0.2.3
182 |
183 | Updates
184 |
185 | * Fixtures for testthat evaluation
186 |
187 | Fixes
188 |
189 | * Specific Windows error during check
190 |
191 | # Version 0.2.2
192 |
193 | Adds
194 |
195 | * Inflation data
196 | * Inflation adjustment function
197 | * Minor changes in vignettes
198 |
199 | # Version 0.2.1
200 |
201 | Fixes
202 |
203 | * Consistent use of colour vs color, color is used from now
204 | * Fixed available tables description
205 | * Adds `yrp_short` to available tables
206 | * Adds `use_localhost` option for our own server or users who want to clone the
207 | database locally, therefore avoid having a separate branh for server
208 | installation
209 |
210 |
--------------------------------------------------------------------------------
/R/ots_cache.R:
--------------------------------------------------------------------------------
1 | #' Caching wrapper to reduce API calls (internal)
2 | #' @description Eases saving the data downloaded from \code{api.tradestatistics.io}
3 | #' and prevents \code{ots_read_from_api()} from downloading the same twice.
4 | #' @param use_cache Logical to save and load from cache. If \code{TRUE}, the results will be cached in memory
5 | #' if \code{file} is \code{NULL} or on disk if `file` is not \code{NULL}.
6 | #' @param file Character with the full file path to save the data.
7 | #' @param ... Additional parameters inherited from \code{ots_create_tidy_data()}.
8 | #' @importFrom data.table fread fwrite
9 | #' @importFrom digest digest
10 | #' @importFrom memoise forget
11 | #' @keywords internal
12 | ots_cache <- function(use_cache, file, ...) {
13 | # cache in memory ----
14 | if (use_cache == TRUE && is.null(file)) {
15 | return(ots_create_tidy_data_memoised(...))
16 | }
17 |
18 | # cache in file ----
19 | if (!is.null(file)) {
20 | hash <- digest(list(body(ots_create_tidy_data_unmemoised), ...))
21 | }
22 |
23 | if (use_cache == TRUE && file.exists(file)) {
24 | d <- fread(file, yaml = TRUE)
25 |
26 | if (d$.hash[1] == hash) {
27 | class(d) <- c("tbl_df", "tbl", "data.frame")
28 | d$.hash <- NULL
29 | return(d)
30 | }
31 | }
32 |
33 | d <- ots_create_tidy_data_unmemoised(...)
34 |
35 | if (!is.null(file)) {
36 | d$.hash <- hash
37 | fwrite(d, file, yaml = TRUE)
38 | d$.hash <- NULL
39 | }
40 |
41 | if (use_cache == FALSE) {
42 | forget(ots_create_tidy_data_memoised)
43 | }
44 |
45 | return(d)
46 | }
47 |
--------------------------------------------------------------------------------
/R/ots_create_tidy_data.R:
--------------------------------------------------------------------------------
1 | #' Downloads and processes the data from the API to return a human-readable tibble
2 | #' @description Accesses \code{api.tradestatistics.io} and
3 | #' performs different API calls to transform and return tidy data.
4 | #' @param years Year contained within the years specified in
5 | #' api.tradestatistics.io/year_range (e.g. \code{c(2002,2004)}, \code{c(2002:2004)} or \code{2002}).
6 | #' Default set to \code{2019}.
7 | #' @param reporters ISO code for reporter country (e.g. \code{"chl"}, \code{"Chile"} or
8 | #' \code{c("chl", "Peru")}). Default set to \code{"all"}.
9 | #' @param partners ISO code for partner country (e.g. \code{"chl"}, \code{"Chile"} or
10 | #' \code{c("chl", "Peru")}). Default set to \code{"all"}.
11 | #' @param commodities HS commodity codes (e.g. \code{"0101"}, \code{"01"} or search
12 | #' matches for \code{"apple"})
13 | #' to filter commodities. Default set to \code{"all"}.
14 | #' @param sections HS section codes (e.g. \code{"01"}). Default set to \code{"all"}.
15 | #' @param table Character string to select the table to obtain the data.
16 | #' Default set to \code{yr} (Year - Reporter).
17 | #' Run \code{ots_tables} in case of doubt.
18 | #' @param max_attempts How many times to try to download data in case the
19 | #' API or the internet connection fails when obtaining data. Default set
20 | #' to \code{5}.
21 | #' @param use_cache Logical to save and load from cache. If \code{TRUE}, the results will be cached in memory
22 | #' if \code{file} is \code{NULL} or on disk if `file` is not \code{NULL}. Default set to \code{FALSE}.
23 | #' @param file Optional character with the full file path to save the data. Default set to \code{NULL}.
24 | #' @return A tibble that describes bilateral trade metrics (imports,
25 | #' exports, trade balance and relevant metrics
26 | #' such as exports growth w/r to last year) between a \code{reporter}
27 | #' and \code{partner} country.
28 | #' @importFrom data.table `:=` rbindlist setnames
29 | #' @importFrom crul HttpClient
30 | #' @export
31 | #' @examples
32 | #' \dontrun{
33 | #' # The next examples can take more than 5 seconds to compute,
34 | #' # so these are just shown without evaluation according to CRAN rules
35 | #'
36 | #' # Run `ots_countries` to display the full table of countries
37 | #' # Run `ots_commodities` to display the full table of commodities
38 | #'
39 | #' # What does Chile export to China? (2002)
40 | #' ots_create_tidy_data(years = 2002, reporters = "chl", partners = "chn")
41 | #'
42 | #' # What can we say about Horses export in Chile and the World? (2002)
43 | #' ots_create_tidy_data(years = 2002, commodities = "010110", table = "yc")
44 | #' ots_create_tidy_data(years = 2002, reporters = "chl", commodities = "010110", table = "yrc")
45 | #'
46 | #' # What can we say about the different types of apples exported by Chile? (2002)
47 | #' ots_create_tidy_data(years = 2002, reporters = "chl", commodities = "apple", table = "yrc")
48 | #' }
49 | #' @keywords functions
50 | ots_create_tidy_data <- function(years = 2020,
51 | reporters = "all",
52 | partners = "all",
53 | commodities = "all",
54 | sections = "all",
55 | table = "yr",
56 | max_attempts = 5,
57 | use_cache = FALSE,
58 | file = NULL) {
59 | if (!is.logical(use_cache)) {
60 | stop("use_cache must be logical.")
61 | }
62 |
63 | if (!any(c(is.null(file), is.character(file)))) {
64 | stop("file must be NULL or character.")
65 | }
66 |
67 | ots_cache(
68 | use_cache = use_cache,
69 | file = file,
70 | years = years,
71 | reporters = reporters,
72 | partners = partners,
73 | commodities = commodities,
74 | sections = sections,
75 | table = table,
76 | max_attempts = max_attempts
77 | )
78 | }
79 |
80 | #' Downloads and processes the data from the API to return a human-readable tibble (unmemoised, internal)
81 | #' @description A separation of \code{ots_create_tidy_data()} for making caching optional.
82 | #' @importFrom utils read.csv
83 | #' @keywords internal
84 | ots_create_tidy_data_unmemoised <- function(years = 2018,
85 | reporters = "usa",
86 | partners = "all",
87 | commodities = "all",
88 | sections = "all",
89 | table = "yr",
90 | max_attempts = 5) {
91 | # Check tables ----
92 | if (!table %in% tradestatistics::ots_tables$table) {
93 | stop("The requested table does not exist. Please check the spelling or explore the 'ots_table' table provided within this package.")
94 | }
95 |
96 | # Check years ----
97 | year_depending_queries <- grep("^reporters|^y|^rtas|^tariffs",
98 | tradestatistics::ots_tables$table,
99 | value = T
100 | )
101 |
102 | year_range <- try(read.csv("https://api.tradestatistics.io/year_range"))
103 | year_range <- try(as.numeric(year_range$year))
104 |
105 | if (all(years %in% min(year_range):max(year_range)) != TRUE &
106 | table %in% year_depending_queries) {
107 | stop("Provided that the table you requested contains a 'year' field, please verify that you are requesting data contained within the years from api.tradestatistics.io/year_range.")
108 | }
109 |
110 | # Check reporters and partners ----
111 | reporter_depending_queries <- grep("^yr|^tariffs",
112 | tradestatistics::ots_tables$table,
113 | value = T
114 | )
115 |
116 | partner_depending_queries <- grep("^yrp|^tariffs",
117 | tradestatistics::ots_tables$table,
118 | value = T
119 | )
120 |
121 | if (!is.null(reporters)) {
122 | if (!all(reporters %in% tradestatistics::ots_countries$country_iso) == TRUE & table %in% reporter_depending_queries) {
123 | reporters_iso <- reporters[reporters %in% tradestatistics::ots_countries$country_iso]
124 | reporters_no_iso <- reporters[!reporters %in% tradestatistics::ots_countries$country_iso]
125 |
126 | reporters_no_iso <- sapply(
127 | seq_along(reporters_no_iso),
128 | function(x) {
129 | y <- tradestatistics::ots_country_code(reporters_no_iso[x])
130 |
131 | if (nrow(y) == 0) {
132 | stop("It was not possible to find ISO codes for any of the reporters you requested. Please check ots_countries.")
133 | } else {
134 | y <- y[, .(country_iso)]
135 | y <- as.vector(unlist(y))
136 | }
137 |
138 | if (length(y) > 1) {
139 | stop("There are multiple matches for the reporters you requested. Please check ots_countries.")
140 | } else {
141 | return(y)
142 | }
143 | }
144 | )
145 |
146 | reporters <- unique(c(reporters_iso, reporters_no_iso))
147 | }
148 | }
149 |
150 | if (!is.null(partners)) {
151 | if (!all(partners %in% tradestatistics::ots_countries$country_iso) == TRUE & table %in% partner_depending_queries) {
152 | partners_iso <- partners[partners %in% tradestatistics::ots_countries$country_iso]
153 | partners_no_iso <- partners[!partners %in% tradestatistics::ots_countries$country_iso]
154 |
155 | partners_no_iso <- sapply(
156 | seq_along(partners_no_iso),
157 | function(x) {
158 | y <- tradestatistics::ots_country_code(partners_no_iso[x])
159 |
160 | if (nrow(y) == 0) {
161 | stop("There are multiple matches for the partners you requested. Please check ots_countries.")
162 | } else {
163 | y <- y[, .(country_iso)]
164 | y <- as.vector(unlist(y))
165 | }
166 |
167 | if (length(y) > 1) {
168 | stop("There are multiple matches for the partners you requested. Please check ots_countries.")
169 | } else {
170 | return(y)
171 | }
172 | }
173 | )
174 |
175 | partners <- unique(c(partners_iso, partners_no_iso))
176 | }
177 | }
178 |
179 | # Check commodity codes ----
180 | commodities_depending_queries <- grep("c$|^tariffs",
181 | tradestatistics::ots_tables$table,
182 | value = T
183 | )
184 |
185 | if (!all(as.character(commodities) %in%
186 | tradestatistics::ots_commodities$commodity_code) == TRUE &
187 | table %in% commodities_depending_queries) {
188 |
189 | # commodities without match (wm)
190 | commodities_wm <- commodities[!commodities %in%
191 | tradestatistics::ots_commodities$commodity_code]
192 |
193 | # commodity name match (pmm)
194 | pnm <- lapply(
195 | seq_along(commodities_wm),
196 | function(x) { tradestatistics::ots_commodity_code(commodity = commodities_wm[x]) }
197 | )
198 | pnm <- rbindlist(pnm)
199 |
200 | # group name match (gnm)
201 | gnm <- lapply(
202 | seq_along(commodities_wm),
203 | function(x) { tradestatistics::ots_commodity_code(group = commodities_wm[x]) }
204 | )
205 | gnm <- rbindlist(gnm)
206 |
207 | commodities_wm <- rbind(pnm, gnm, fill = TRUE)
208 | commodities_wm <- unique(commodities_wm[nchar(commodity_code) == 4, .(commodity_code)])
209 | commodities_wm <- as.vector(unlist(commodities_wm))
210 |
211 | commodities <- c(commodities[commodities %in%
212 | tradestatistics::ots_commodities$commodity_code], commodities_wm)
213 |
214 | if(length(commodities) == 0) {
215 | commodities <- NA
216 | }
217 | }
218 |
219 | if (!all(as.character(commodities) %in%
220 | tradestatistics::ots_commodities$commodity_code == TRUE) &
221 | table %in% commodities_depending_queries) {
222 | stop("The requested commodities do not exist. Please check ots_commodities.")
223 | }
224 |
225 | # Check section codes -----------------------------------------------------
226 | sections <- sort(as.character(sections))
227 |
228 | if (!all(sections %in% c(tradestatistics::ots_sections$section_code, "all") == TRUE) &
229 | table %in% commodities_depending_queries) {
230 | for (i in seq_along(sections)) {
231 | if (sections[i] != "all") {
232 | sections[i] <- as.integer(substr(sections, 1, 3))
233 | }
234 | if (nchar(sections[i]) != 2 & sections[i] != "999") {
235 | sections[i] <- paste0("0", sections[i])
236 | }
237 | }
238 |
239 | for (i in seq_along(sections)) {
240 | sections[i] <- if (!sections[i] %in% tradestatistics::ots_sections$section_code) {
241 | NA
242 | } else {
243 | sections[i]
244 | }
245 | }
246 |
247 | sections <- sections[!is.na(sections)]
248 | if(length(sections) == 0) {
249 | sections <- NA
250 | }
251 | }
252 |
253 | if (!all(sections %in% c(tradestatistics::ots_sections$section_code, "all") == TRUE) &
254 | table %in% commodities_depending_queries) {
255 | stop("The requested sections do not exist. Please check ots_sections.")
256 | }
257 |
258 | # Check optional parameters ----
259 | if (!is.numeric(max_attempts) | max_attempts <= 0) {
260 | stop("max_attempts must be a positive integer.")
261 | }
262 |
263 | # Read from API ----
264 | if (!table %in% commodities_depending_queries & any(commodities != "all") == TRUE) {
265 | commodities <- "all"
266 | warning("The commodities argument will be ignored provided that you requested a table without commodity_code field.")
267 | }
268 |
269 | if (is.null(reporters)) {
270 | reporters <- "all"
271 | warning("No reporter was specified, therefore all available reporters will be returned.")
272 | }
273 |
274 | if (is.null(partners)) {
275 | partners <- "all"
276 | warning("No partner was specified, therefore all available partners will be returned.")
277 | }
278 |
279 | condensed_parameters <- expand.grid(
280 | year = years,
281 | reporter = reporters,
282 | partner = partners,
283 | commodity = commodities,
284 | section = "all",
285 | stringsAsFactors = FALSE
286 | )
287 |
288 | data <- lapply(
289 | seq_len(nrow(condensed_parameters)),
290 | function(x) {
291 | ots_read_from_api(
292 | table = table,
293 | max_attempts = max_attempts,
294 | year = condensed_parameters$year[x],
295 | reporter_iso = condensed_parameters$reporter[x],
296 | partner_iso = condensed_parameters$partner[x],
297 | commodity_code = condensed_parameters$commodity[x],
298 | section_code = condensed_parameters$section[x]
299 | )
300 | }
301 | )
302 | data <- rbindlist(data, fill = TRUE)
303 |
304 | # no data in API message
305 | if (any("observation" %in% names(data))) {
306 | warning("The parameters you specified resulted in API calls returning 0 rows.")
307 | return(data)
308 | }
309 |
310 | # Add attributes based on codes, etc (and join years, if applicable) ------
311 |
312 | # include countries data
313 | if (table %in% reporter_depending_queries) {
314 | data <- merge(data, tradestatistics::ots_countries[, .(country_iso, country_name_english)],
315 | all.x = TRUE, all.y = FALSE,
316 | by.x = "reporter_iso", by.y = "country_iso",
317 | allow.cartesian = TRUE)
318 | data <- setnames(data, "country_name_english", "reporter_name")
319 | }
320 |
321 | if (table %in% partner_depending_queries) {
322 | data <- merge(data, tradestatistics::ots_countries[, .(country_iso, country_name_english)],
323 | all.x = TRUE, all.y = FALSE,
324 | by.x = "partner_iso", by.y = "country_iso",
325 | allow.cartesian = TRUE)
326 | data <- setnames(data, "country_name_english", "partner_name")
327 | }
328 |
329 | # include commodities data
330 | if (table %in% commodities_depending_queries) {
331 | data <- merge(data, tradestatistics::ots_commodities,
332 | all.x = TRUE, all.y = FALSE,
333 | by.x = c("commodity_code", "section_code"), by.y = c("commodity_code", "section_code"),
334 | allow.cartesian = TRUE)
335 |
336 | data <- merge(data, tradestatistics::ots_sections,
337 | all.x = TRUE, all.y = FALSE,
338 | by.x = "section_code", by.y = "section_code",
339 | allow.cartesian = TRUE
340 | )
341 |
342 | data <- setnames(data, c("commodity_fullname_english", "section_fullname_english"),
343 | c("commodity_name", "section_name"))
344 | }
345 |
346 | columns_order <- c("year",
347 | grep("^reporter_", colnames(data), value = TRUE),
348 | grep("^partner_", colnames(data), value = TRUE),
349 | grep("^commodity_", colnames(data), value = TRUE),
350 | grep("^section_", colnames(data), value = TRUE),
351 | grep("^trade_", colnames(data), value = TRUE),
352 | grep("^country|^rta", colnames(data), value = TRUE),
353 | grep("tariff|source", colnames(data), value = TRUE)
354 | )
355 |
356 | data <- data[, ..columns_order]
357 |
358 | return(data)
359 | }
360 |
361 | #' Downloads and processes the data from the API to return a human-readable tibble (memoised, internal)
362 | #' @description A composition of \code{ots_create_tidy_data_unmemoised()} and \code{memoise()} for caching the output
363 | #' @importFrom memoise memoise
364 | #' @keywords internal
365 | ots_create_tidy_data_memoised <- memoise::memoise(ots_create_tidy_data_unmemoised)
366 |
--------------------------------------------------------------------------------
/R/ots_gdp_deflator_adjustment.R:
--------------------------------------------------------------------------------
1 | #' Expresses tidy data from the API in dollars of a reference year
2 | #' @description Uses GDP deflator records from The World Bank to
3 | #' convert trade records and express them in dollars of the same year. The
4 | #' records are internally subsetted to World's values, because country specific
5 | #' levels would largely re-scale observations for reporters that reflect
6 | #' unstable macroeconomic policies.
7 | #' @param trade_data A tibble obtained by using ots_create_tidy_data.
8 | #' Default set to \code{NULL}.
9 | #' @param reference_year Year contained within the years specified in
10 | #' api.tradestatistics.io/year_range (e.g. \code{2010}).
11 | #' Default set to \code{NULL}.
12 | #' @importFrom data.table `:=` rbindlist last
13 | #' @export
14 | #' @examples
15 | #' \dontrun{
16 | #' # The next example can take more than 5 seconds to compute,
17 | #' # so this is shown without evaluation according to CRAN rules
18 | #'
19 | #' # Convert dollars of 2010 to dollars of 2000
20 | #' d <- ots_create_tidy_data(years = 2010, reporters = "chl", partners = "chn")
21 | #' ots_gdp_deflator_adjustment(trade_data = d, reference_year = 2000)
22 | #' }
23 | #' @keywords functions
24 | ots_gdp_deflator_adjustment <- function(trade_data = NULL, reference_year = NULL) {
25 | # Check input -------------------------------------------------------------
26 | if (is.null(trade_data)) {
27 | stop("The input data cannot be NULL.")
28 | }
29 |
30 | if (is.null(reference_year)) {
31 | stop("The reference year cannot be NULL."
32 | )
33 | }
34 |
35 | ots_gdp_deflator_min_year <- min(tradestatistics::ots_gdp_deflator$year_from)
36 | ots_gdp_deflator_max_year <- max(tradestatistics::ots_gdp_deflator$year_from)
37 |
38 | if (!is.numeric(reference_year) |
39 | !(reference_year >= ots_gdp_deflator_min_year &
40 | reference_year <= ots_gdp_deflator_max_year)) {
41 | stop(sprintf("The reference year must be numeric and contained within ots_gdp_deflator years range that is %s-%s.",
42 | ots_gdp_deflator_min_year,
43 | ots_gdp_deflator_max_year
44 | )
45 | )
46 | }
47 |
48 | # Filter year conversion rates and join data ------------------------------
49 | years <- unique(trade_data$year)
50 |
51 | d1 <- lapply(
52 | years,
53 | function(year) {
54 | if (year < reference_year) {
55 | tradestatistics::ots_gdp_deflator[year_to <= reference_year &
56 | year_to > year & country_iso == "wld",
57 | .(gdp_deflator = last(cumprod(gdp_deflator)))][,
58 | `:=`(year = ..year, conversion_year = ..reference_year)][,
59 | .(year, conversion_year, gdp_deflator)]
60 | } else if (year > reference_year) {
61 | tradestatistics::ots_gdp_deflator[year_from >= reference_year &
62 | year_from < year &
63 | country_iso == "wld",
64 | .(gdp_deflator = 1/last(cumprod(gdp_deflator)))][,
65 | `:=`(year = ..year, conversion_year = ..reference_year)][,
66 | .(year, conversion_year, gdp_deflator)]
67 | } else if (year == reference_year) {
68 | data.frame(
69 | year = year, conversion_year = year, gdp_deflator = 1
70 | )
71 | }
72 | }
73 | )
74 | d1 <- rbindlist(d1)
75 |
76 | d2 <- trade_data[d1, on = .(year), allow.cartesian = TRUE][,
77 | `:=`(trade_value_usd_exp = round(trade_value_usd_exp * gdp_deflator, 0),
78 | trade_value_usd_imp = round(trade_value_usd_imp * gdp_deflator, 0))]
79 |
80 | return(d2)
81 | }
82 |
--------------------------------------------------------------------------------
/R/ots_license_message.R:
--------------------------------------------------------------------------------
1 | .onAttach <- function(libname, pkgname) {
2 | packageStartupMessage(
3 | "
4 | Welcome to tradestatistics package. Visit tradestatistics.io to check the
5 | code of conduct and full-detail tables available in direct download.
6 |
7 | Commercial purposes are strictly out of the boundaries of what you
8 | can do with this data according to UN Comtrade dissemination clauses.
9 |
10 | Our data is distributed under Creative Commons
11 | Attribution-NonCommercial 4.0 International License.
12 | "
13 | )
14 | }
15 |
--------------------------------------------------------------------------------
/R/ots_read_from_api.R:
--------------------------------------------------------------------------------
1 | #' Reads data from the API (internal function)
2 | #' @description Accesses \code{api.tradestatistics.io} and
3 | #' performs different API calls to return \code{data.frames} by reading
4 | #' \code{JSON} data. The parameters here are passed from
5 | #' \code{ots_create_tidy_data}.
6 | #' @importFrom crul HttpClient
7 | #' @importFrom jsonlite fromJSON
8 | #' @keywords internal
9 | ots_read_from_api <- function(year = NULL,
10 | reporter_iso = NULL,
11 | partner_iso = NULL,
12 | commodity_code = "all",
13 | section_code = "all",
14 | table = "yr",
15 | max_attempts = 5) {
16 | stopifnot(max_attempts > 0)
17 |
18 | if (any(table %in% c("countries", "commodities", "commodities_short", "sections", "sections_colors", "tables", "distances"))) {
19 | message("The requested table is included within the package.")
20 | return(TRUE)
21 | }
22 |
23 | url <- switch(
24 | table,
25 | "reporters" = sprintf("reporters?y=%s", year),
26 | "partners" = sprintf("partners?y=%s", year),
27 | "yrpc" = sprintf("yrpc?y=%s&r=%s&p=%s&c=%s", year, reporter_iso, partner_iso, commodity_code),
28 | "yrp" = sprintf("yrp?y=%s&r=%s&p=%s", year, reporter_iso, partner_iso),
29 | "yrc" = sprintf("yrc?y=%s&r=%s&c=%s", year, reporter_iso, commodity_code),
30 | "yr" = sprintf("yr?y=%s&r=%s", year, reporter_iso),
31 | "yc" = sprintf("yc?y=%s&c=%s", year, commodity_code)
32 | )
33 |
34 | base_url <- "https://api.tradestatistics.io/"
35 |
36 | resp <- HttpClient$new(url = base_url)
37 | resp <- resp$get(url)
38 |
39 | # on a successful GET, return the response
40 | if (resp$status_code == 200) {
41 | combination <- paste(year, reporter_iso, partner_iso, sep = ", ")
42 |
43 | if (commodity_code != "all") {
44 | combination <- paste(combination, commodity_code, sep = ", ")
45 | }
46 |
47 | message(sprintf("Downloading data for the combination %s...", combination))
48 |
49 | data <- try(fromJSON(resp$parse(encoding = "UTF-8")))
50 |
51 | if (!is.data.frame(data)) {
52 | stop("It wasn't possible to obtain data. Provided this function tests your internet connection\nyou misspelled a reporter, partner or table, or there was a server problem. Please check and try again.")
53 | }
54 |
55 | return(data)
56 | } else if (max_attempts == 0) {
57 | # when attempts run out, stop with an error
58 | stop("Cannot connect to the API. Either the server is down or there is a connection problem.")
59 | } else {
60 | # otherwise, sleep five seconds and try again
61 | Sys.sleep(5)
62 | ots_read_from_api(year, reporter_iso, partner_iso, commodity_code, table,
63 | max_attempts = max_attempts - 1)
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/R/ots_strings_processing.R:
--------------------------------------------------------------------------------
1 | #' String matching of official country names and ISO-3 codes according to
2 | #' the United Nations nomenclature
3 | #' @description Takes a text string and searches within the
4 | #' package data for a country code in the context of valid API country codes.
5 | #' @param countryname A text string such as "Chile", "CHILE" or "CHL".
6 | #' @return A single character if there is a exact match (e.g.
7 | #' \code{ots_country_code("Chile")}) or a tibble in case of multiple matches
8 | #' (e.g. \code{ots_country_code("Germany")})
9 | #' @export
10 | #' @examples
11 | #' ots_country_code("Chile ")
12 | #' ots_country_code("america")
13 | #' ots_country_code("UNITED STATES")
14 | #' ots_country_code(" united_")
15 | #' @keywords functions
16 | ots_country_code <- function(countryname = NULL) {
17 | if (is.null(countryname)) {
18 | stop("'countryname' is NULL.")
19 | } else {
20 | stopifnot(is.character(countryname))
21 |
22 | countryname <- iconv(countryname, to = "ASCII//TRANSLIT", sub = " ")
23 | countryname <- gsub("[^[:alpha:]]", "", countryname)
24 | countryname <- tolower(countryname)
25 | }
26 |
27 | countryname <- switch(
28 | countryname,
29 | "us" = "usa",
30 | "america" = "usa",
31 | "united states" = "usa",
32 | "united states of america" = "usa",
33 | "uk" = "united kingdom",
34 | "england" = "united kingdom",
35 | "scotland" = "united kingdom",
36 | "holland" = "netherlands",
37 | "myanmar" = "burma",
38 | "persia" = "iran",
39 | "siam" = "thailand",
40 | "indochina" = "vietnam",
41 | "rhodesia" = "zimbabwe",
42 | "british honduras" = "belice",
43 | "bengal" = "bangladesh",
44 | "east pakistan" = "bangladesh",
45 | "zaire" = "democratic republic of the congo",
46 | countryname
47 | )
48 |
49 | if (countryname == "") {
50 | stop("The input results in an empty string after removing multiple spaces and special symbols. Please check the spelling or explore the countries table provided within this package.")
51 | } else {
52 | countrycode <- tradestatistics::ots_countries[grepl(countryname, tolower(country_fullname_english))]
53 | }
54 |
55 | return(countrycode)
56 | }
57 |
58 | #' String matching of official commodity/section names and Harmonized System (HS) codes
59 | #' according to the United Nations nomenclature
60 | #' @description Takes a text string and searches within the
61 | #' package data for all matching commodity codes in the context of valid API
62 | #' commodity codes.
63 | #' @param commodity A text string such as "Animals", "COPPER" or "fruits".
64 | #' @param section A text string such as "meat", "FISH" or "Dairy".
65 | #' @return A tibble with all possible matches (no uppercase distinction)
66 | #' showing the commodity name and commodity code
67 | #' @export
68 | #' @examples
69 | #' ots_commodity_code(commodity = "ANIMALS ")
70 | #' ots_commodity_code(section = " fish")
71 | #' ots_commodity_code(commodity = "Milk", section = "Dairy")
72 | #' @keywords functions
73 | ots_commodity_code <- function(commodity = NULL, section = NULL) {
74 | if (is.null(commodity) & is.null(section)) {
75 | stop("'commodity' and 'section' are NULL.")
76 | }
77 |
78 | if (!is.null(commodity) & is.null(section)) {
79 | stopifnot(is.character(commodity))
80 | # stopifnot(nchar(commodity) > 0)
81 |
82 | commodity <- tolower(iconv(commodity, to = "ASCII//TRANSLIT", sub = ""))
83 | commodity <- gsub("[^[:alpha:]]", "", commodity)
84 |
85 | if (commodity == "") {
86 | stop("The input results in an empty string after removing multiple spaces and special symbols. Please check the spelling or explore the commodities table provided within this package.")
87 | } else {
88 | d <- tradestatistics::ots_commodities[grepl(commodity, tolower(commodity_fullname_english)), c("commodity_code", "commodity_fullname_english")]
89 | }
90 | }
91 |
92 | if (is.null(commodity) & !is.null(section)) {
93 | stopifnot(is.character(section))
94 |
95 | section <- tolower(iconv(section, to = "ASCII//TRANSLIT", sub = ""))
96 | section <- gsub("[^[:alpha:]]", "", section)
97 |
98 | if (section == "") {
99 | stop("The input results in an empty string after removing multiple spaces and special symbols. Please check the spelling or explore the commodities table provided within this package.")
100 | } else {
101 | d <- tradestatistics::ots_sections[grepl(section, tolower(section_fullname_english))]
102 | }
103 | }
104 |
105 | if (!is.null(commodity) & !is.null(section)) {
106 | stopifnot(is.character(commodity))
107 | # stopifnot(nchar(commodity) > 0)
108 |
109 | stopifnot(is.character(section))
110 | # stopifnot(nchar(section) > 0)
111 |
112 | commodity <- tolower(iconv(commodity, to = "ASCII//TRANSLIT", sub = ""))
113 | commodity <- gsub("[^[:alpha:]]", "", commodity)
114 |
115 | section <- tolower(iconv(section, to = "ASCII//TRANSLIT", sub = ""))
116 | section <- gsub("[^[:alpha:]]", "", section)
117 |
118 | if (commodity == "" | section == "") {
119 | stop("The input results in an empty string after removing multiple spaces and special symbols. Please check the spelling or explore the commodities table provided within this package.")
120 | } else {
121 | # d <- tradestatistics::ots_commodities[
122 | # grepl(commodity, tolower(commodity_fullname_english)) &
123 | # grepl(section, tolower(section_fullname_english))]
124 |
125 | d <- merge(
126 | tradestatistics::ots_commodities[
127 | grepl(commodity, tolower(commodity_fullname_english))],
128 | tradestatistics::ots_sections[
129 | grepl(section, tolower(section_fullname_english))],
130 | by = "section_code"
131 | )
132 | }
133 | }
134 |
135 | return(d)
136 | }
137 |
--------------------------------------------------------------------------------
/R/tradestatistics-package.R:
--------------------------------------------------------------------------------
1 | #' @keywords internal
2 | "_PACKAGE"
3 |
4 | utils::globalVariables(c(
5 | "year", "country_iso",
6 | "country_name_english", "country_fullname_english",
7 | "commodity_fullname_english", "section_fullname_english", "commodity_code",
8 | "group_code", "trade_value_usd_exp", "trade_value_usd_imp",
9 | "trade_value_usd_top_exp", "trade_value_usd_top_imp",
10 | "gdp_deflator", "conversion_factor", "conversion_year", "year_from",
11 | "year_to", "observation", "..group", "..productname", "..section",
12 | "..reference_year", "..year", "..columns_order", "."
13 | ))
14 |
15 | #' OTS Tables
16 | #'
17 | #' Existing API tables with both description and source.
18 | #'
19 | #' @docType data
20 | #' @keywords datasets
21 | #' @name ots_tables
22 | #' @usage ots_tables
23 | #' @source Open Trade Statistics
24 | #' @format A data frame with 12 rows and 3 variables
25 | #' \describe{
26 | #' \item{\code{table}}{Table name}
27 | #' \item{\code{description}}{Description of table contents}
28 | #' \item{\code{source}}{Source for the data (OTS tables are processed after UN Comtrade raw data)}
29 | #' }
30 | NULL
31 |
32 | #' GDP Deflator
33 | #'
34 | #' Year to year GDP deflator some of the countries in the OTS database. For
35 | #' countries not available in the World Bank database, rows labelled as "wld"
36 | #' are provided, which were computed as the weighted median for each year using
37 | #' the GDP of listed countries for each year expressed as constant dollars of
38 | #' the year 2010.
39 | #'
40 | #' @docType data
41 | #' @keywords datasets
42 | #' @name ots_gdp_deflator
43 | #' @usage ots_gdp_deflator
44 | #' @source Open Trade Statistics
45 | #' @format A data frame with 8,010 observations on the following 4 variables
46 | #' \describe{
47 | #' \item{\code{year_from}}{Integer values in the range 1980-2020}
48 | #' \item{\code{year_to}}{Integer values in the range 1981-2021}
49 | #' \item{\code{country_iso}}{ISO code of the country (e.g. "chl" means Chile)}
50 | #' \item{\code{gdp_deflator}}{Numeric value expressed as one plus 1-year deflator}
51 | #' }
52 | NULL
53 |
54 | #' OTS Countries
55 | #'
56 | #' Official country names, ISO-3 codes, continent and EU membership.
57 | #'
58 | #' @docType data
59 | #' @keywords datasets
60 | #' @name ots_countries
61 | #' @usage ots_countries
62 | #' @source Open Trade Statistics
63 | #' @format A data frame with 275 observations on the following 5 variables
64 | #' \describe{
65 | #' \item{\code{country_iso}}{ISO-3 code of the country (e.g. "deu" means Germany)}
66 | #' \item{\code{country_name_english}}{Country name (e.g. Germany)}
67 | #' \item{\code{country_fullname_english}}{Country name with indications (e.g. Germany as "Germany (former Federal Republic of Germany until 1990)")}
68 | #' \item{\code{continent_name_english}}{Continent where the country belongs to (e.g., Europe)}
69 | #' \item{\code{continent_id}}{Numeric id of the continent where the country belongs to (e.g., 5)}
70 | #' }
71 | NULL
72 |
73 | #' OTS Countries Colors
74 | #'
75 | #' Unofficial colors to ease visualization for countries.
76 | #'
77 | #' @docType data
78 | #' @keywords datasets
79 | #' @name ots_countries_colors
80 | #' @usage ots_countries_colors
81 | #' @source Open Trade Statistics
82 | #' @format A data frame with 275 rows and 3 variables
83 | #' \describe{
84 | #' \item{\code{country_iso}}{ISO code of the country (e.g. "chl" means Chile)}
85 | #' \item{\code{continent_id}}{Numeric id of the continent}
86 | #' \item{\code{country_color}}{Country hex color (e.g. '#D05555')}
87 | #' }
88 | NULL
89 |
90 | #' OTS Commodities
91 | #'
92 | #' Official commodity names from the Harmonized System rev 2012
93 | #' (HS12, six digits detail).
94 | #'
95 | #' @docType data
96 | #' @keywords datasets
97 | #' @name ots_commodities
98 | #' @usage ots_commodities
99 | #' @source Open Trade Statistics
100 | #' @format A data frame with 5,302 observations on the following 4 variables
101 | #' \describe{
102 | #' \item{\code{commodity_code}}{HS six digits commodity code (e.g. 010110)}
103 | #' \item{\code{commodity_code_short}}{HS four digits commodity code (e.g. 0101)}
104 | #' \item{\code{commodity_fullname_english}}{HS six digits commodity name (e.g. 'Horses, asses, mules and hinnies; live, pure-bred breeding animals')}
105 | #' \item{\code{section_code}}{HS section code (e.g. '01')}
106 | #' }
107 | NULL
108 |
109 | #' OTS Commodities Short
110 | #'
111 | #' Official commodity names from the Harmonized System rev 2012
112 | #' (HS12, four digits detail).
113 | #'
114 | #' @docType data
115 | #' @keywords datasets
116 | #' @name ots_commodities_short
117 | #' @usage ots_commodities_short
118 | #' @source Open Trade Statistics
119 | #' @format A data frame with 1,225 observations on the following 2 variables
120 | #' \describe{
121 | #' \item{\code{commodity_code}}{HS four digits commodity code (e.g. 0101)}
122 | #' \item{\code{commodity_fullname_english}}{HS four digits commodity names (e.g. 'Horses, asses, mules and hinnies; live')}
123 | #' }
124 | NULL
125 |
126 | #' OTS Sections
127 | #'
128 | #' Official section names from the Harmonized System rev 2012 (HS12).
129 | #'
130 | #' @docType data
131 | #' @keywords datasets
132 | #' @name ots_sections
133 | #' @usage ots_sections
134 | #' @source Adapted from UN COMTRADE
135 | #' @format A data frame with 22 rows and 2 variables
136 | #' \describe{
137 | #' \item{\code{section_code}}{HS section code (e.g. '01')}
138 | #' \item{\code{section_fullname_english}}{HS section name (e.g. 'Live animals and animal products')}
139 | #' }
140 | NULL
141 |
142 | #' OTS Sections Colors
143 | #'
144 | #' Unofficial colors to ease visualization for the sections in
145 | #' the Harmonized System rev 2012 (HS12).
146 | #'
147 | #' @docType data
148 | #' @keywords datasets
149 | #' @name ots_sections_colors
150 | #' @usage ots_sections_colors
151 | #' @source Open Trade Statistics
152 | #' @format A data frame with 22 rows and 2 variables
153 | #' \describe{
154 | #' \item{\code{section_code}}{HS section code (e.g. '01')}
155 | #' \item{\code{section_color}}{HS section color (e.g. '#74c0e2')}
156 | #' }
157 | NULL
158 |
--------------------------------------------------------------------------------
/README.Rmd:
--------------------------------------------------------------------------------
1 | ---
2 | output: github_document
3 | ---
4 |
5 |
6 |
7 | ```{r, echo = FALSE}
8 | knitr::opts_chunk$set(
9 | collapse = TRUE,
10 | comment = "#>",
11 | fig.path = "man/figures/"
12 | )
13 | ```
14 |
15 | # Open Trade Statistics package
16 |
17 | [](https://www.repostatus.org/#active)
18 | [](https://www.tidyverse.org/lifecycle/#stable)
19 | [](https://github.com/ropensci/tradestatistics/actions?workflow=R-CMD-check)
20 | [](https://cran.r-project.org/package=tradestatistics)
21 | [](https://codecov.io/github/ropensci/tradestatistics?branch=master)
22 | [](https://github.com/ropensci/onboarding/issues/274)
23 |
24 | [Open Trade Statistics](https://tradestatistics.io) is an effort to open international trade data. `tradestatistics` provides an easy way to obtain data from OTS by accessing its API.
25 |
26 | This is what the package does:
27 |
28 | 
29 |
30 | Using `tradestatistics` package is all about efficiency, without this package you could obtain the same data from the API at the expense of using additional time and effort for the same results. As an API wrapper and utility program this package makes data obtaining faster and easier for you.
31 |
32 | ## Installation
33 |
34 | ```{r, eval = FALSE}
35 | # Install stable version from CRAN
36 | install.packages("tradestatistics")
37 |
38 | # Install stable version from GitHub
39 | devtools::install_github("ropensci/tradestatistics")
40 | ```
41 |
42 | ## Code of conduct
43 |
44 | Please note that this project is released with a [Contributor Code of Conduct](https://docs.ropensci.org/tradestatistics/CODE_OF_CONDUCT.html).
45 | By participating in this project you agree to abide by its terms.
46 |
47 | [](https://ropensci.org)
48 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | # Open Trade Statistics package
5 |
6 | [](https://www.repostatus.org/#active)
9 | [](https://www.tidyverse.org/lifecycle/#stable)
11 | [](https://github.com/ropensci/tradestatistics/actions?workflow=R-CMD-check)
13 | [](https://cran.r-project.org/package=tradestatistics)
15 | [](https://codecov.io/github/ropensci/tradestatistics?branch=master)
17 | [](https://github.com/ropensci/onboarding/issues/274)
18 |
19 | [Open Trade Statistics](https://tradestatistics.io) is an effort to open
20 | international trade data. `tradestatistics` provides an easy way to
21 | obtain data from OTS by accessing its API.
22 |
23 | This is what the package does:
24 |
25 | 
26 |
27 | Using `tradestatistics` package is all about efficiency, without this
28 | package you could obtain the same data from the API at the expense of
29 | using additional time and effort for the same results. As an API wrapper
30 | and utility program this package makes data obtaining faster and easier
31 | for you.
32 |
33 | ## Installation
34 |
35 | ``` r
36 | # Install stable version from CRAN
37 | install.packages("tradestatistics")
38 |
39 | # Install stable version from GitHub
40 | devtools::install_github("ropensci/tradestatistics")
41 | ```
42 |
43 | ## Code of conduct
44 |
45 | Please note that this project is released with a [Contributor Code of
46 | Conduct](https://docs.ropensci.org/tradestatistics/CODE_OF_CONDUCT.html).
47 | By participating in this project you agree to abide by its terms.
48 |
49 | [](https://ropensci.org)
50 |
--------------------------------------------------------------------------------
/_pkgdown.yml:
--------------------------------------------------------------------------------
1 | template:
2 | package: rotemplate
3 |
4 | destination: docs
5 |
6 | toc:
7 | depth: 3
8 |
--------------------------------------------------------------------------------
/codecov.yml:
--------------------------------------------------------------------------------
1 | comment: false
2 |
3 | coverage:
4 | status:
5 | project:
6 | default:
7 | target: auto
8 | threshold: 1%
9 | patch:
10 | default:
11 | target: auto
12 | threshold: 1%
13 | ignore:
14 | - "R/ots_read_from_api.R" # this internal function is called from end-user functions
15 |
--------------------------------------------------------------------------------
/codemeta.json:
--------------------------------------------------------------------------------
1 | {
2 | "@context": "https://doi.org/10.5063/schema/codemeta-2.0",
3 | "@type": "SoftwareSourceCode",
4 | "identifier": "tradestatistics",
5 | "description": "Access 'Open Trade Statistics' API from R to download international trade data.",
6 | "name": "tradestatistics: Open Trade Statistics API Wrapper and Utility Program",
7 | "codeRepository": "https://docs.ropensci.org/tradestatistics/",
8 | "issueTracker": "https://github.com/ropensci/tradestatistics/issues/",
9 | "license": "Apache License 2",
10 | "version": "4.4.0",
11 | "programmingLanguage": {
12 | "@type": "ComputerLanguage",
13 | "name": "R",
14 | "url": "https://r-project.org"
15 | },
16 | "runtimePlatform": "R version 4.2.1 (2022-06-23)",
17 | "provider": {
18 | "@id": "https://cran.r-project.org",
19 | "@type": "Organization",
20 | "name": "Comprehensive R Archive Network (CRAN)",
21 | "url": "https://cran.r-project.org"
22 | },
23 | "author": [
24 | {
25 | "@type": "Person",
26 | "givenName": "Mauricio",
27 | "familyName": "Vargas",
28 | "email": "mavargas11@uc.cl",
29 | "@id": "https://orcid.org/0000-0003-1017-7574"
30 | }
31 | ],
32 | "contributor": [
33 | {
34 | "@type": "Person",
35 | "givenName": "Joshua",
36 | "familyName": "Kunst"
37 | },
38 | {
39 | "@type": "Person",
40 | "givenName": "Alexey",
41 | "familyName": "Kravchenko"
42 | },
43 | {
44 | "@type": "Person",
45 | "givenName": "Emma",
46 | "familyName": "Mendelsohn"
47 | },
48 | {
49 | "@type": "Person",
50 | "givenName": "Daniela",
51 | "familyName": "de los Santos"
52 | },
53 | {
54 | "@type": "Organization",
55 | "name": "UN Comtrade"
56 | },
57 | {
58 | "@type": "Organization",
59 | "name": "The World Bank"
60 | }
61 | ],
62 | "copyrightHolder": [
63 | {
64 | "@type": "Person",
65 | "givenName": "Mauricio",
66 | "familyName": "Vargas",
67 | "email": "mavargas11@uc.cl",
68 | "@id": "https://orcid.org/0000-0003-1017-7574"
69 | }
70 | ],
71 | "maintainer": [
72 | {
73 | "@type": "Person",
74 | "givenName": "Mauricio",
75 | "familyName": "Vargas",
76 | "email": "mavargas11@uc.cl",
77 | "@id": "https://orcid.org/0000-0003-1017-7574"
78 | }
79 | ],
80 | "softwareSuggestions": [
81 | {
82 | "@type": "SoftwareApplication",
83 | "identifier": "knitr",
84 | "name": "knitr",
85 | "provider": {
86 | "@id": "https://cran.r-project.org",
87 | "@type": "Organization",
88 | "name": "Comprehensive R Archive Network (CRAN)",
89 | "url": "https://cran.r-project.org"
90 | },
91 | "sameAs": "https://CRAN.R-project.org/package=knitr"
92 | },
93 | {
94 | "@type": "SoftwareApplication",
95 | "identifier": "rmarkdown",
96 | "name": "rmarkdown",
97 | "provider": {
98 | "@id": "https://cran.r-project.org",
99 | "@type": "Organization",
100 | "name": "Comprehensive R Archive Network (CRAN)",
101 | "url": "https://cran.r-project.org"
102 | },
103 | "sameAs": "https://CRAN.R-project.org/package=rmarkdown"
104 | },
105 | {
106 | "@type": "SoftwareApplication",
107 | "identifier": "tibble",
108 | "name": "tibble",
109 | "provider": {
110 | "@id": "https://cran.r-project.org",
111 | "@type": "Organization",
112 | "name": "Comprehensive R Archive Network (CRAN)",
113 | "url": "https://cran.r-project.org"
114 | },
115 | "sameAs": "https://CRAN.R-project.org/package=tibble"
116 | },
117 | {
118 | "@type": "SoftwareApplication",
119 | "identifier": "testthat",
120 | "name": "testthat",
121 | "version": ">= 2.1.0",
122 | "provider": {
123 | "@id": "https://cran.r-project.org",
124 | "@type": "Organization",
125 | "name": "Comprehensive R Archive Network (CRAN)",
126 | "url": "https://cran.r-project.org"
127 | },
128 | "sameAs": "https://CRAN.R-project.org/package=testthat"
129 | },
130 | {
131 | "@type": "SoftwareApplication",
132 | "identifier": "vcr",
133 | "name": "vcr",
134 | "provider": {
135 | "@id": "https://cran.r-project.org",
136 | "@type": "Organization",
137 | "name": "Comprehensive R Archive Network (CRAN)",
138 | "url": "https://cran.r-project.org"
139 | },
140 | "sameAs": "https://CRAN.R-project.org/package=vcr"
141 | },
142 | {
143 | "@type": "SoftwareApplication",
144 | "identifier": "covr",
145 | "name": "covr",
146 | "provider": {
147 | "@id": "https://cran.r-project.org",
148 | "@type": "Organization",
149 | "name": "Comprehensive R Archive Network (CRAN)",
150 | "url": "https://cran.r-project.org"
151 | },
152 | "sameAs": "https://CRAN.R-project.org/package=covr"
153 | }
154 | ],
155 | "softwareRequirements": {
156 | "1": {
157 | "@type": "SoftwareApplication",
158 | "identifier": "crul",
159 | "name": "crul",
160 | "provider": {
161 | "@id": "https://cran.r-project.org",
162 | "@type": "Organization",
163 | "name": "Comprehensive R Archive Network (CRAN)",
164 | "url": "https://cran.r-project.org"
165 | },
166 | "sameAs": "https://CRAN.R-project.org/package=crul"
167 | },
168 | "2": {
169 | "@type": "SoftwareApplication",
170 | "identifier": "arrow",
171 | "name": "arrow",
172 | "provider": {
173 | "@id": "https://cran.r-project.org",
174 | "@type": "Organization",
175 | "name": "Comprehensive R Archive Network (CRAN)",
176 | "url": "https://cran.r-project.org"
177 | },
178 | "sameAs": "https://CRAN.R-project.org/package=arrow"
179 | },
180 | "3": {
181 | "@type": "SoftwareApplication",
182 | "identifier": "memoise",
183 | "name": "memoise",
184 | "provider": {
185 | "@id": "https://cran.r-project.org",
186 | "@type": "Organization",
187 | "name": "Comprehensive R Archive Network (CRAN)",
188 | "url": "https://cran.r-project.org"
189 | },
190 | "sameAs": "https://CRAN.R-project.org/package=memoise"
191 | },
192 | "4": {
193 | "@type": "SoftwareApplication",
194 | "identifier": "data.table",
195 | "name": "data.table",
196 | "provider": {
197 | "@id": "https://cran.r-project.org",
198 | "@type": "Organization",
199 | "name": "Comprehensive R Archive Network (CRAN)",
200 | "url": "https://cran.r-project.org"
201 | },
202 | "sameAs": "https://CRAN.R-project.org/package=data.table"
203 | },
204 | "5": {
205 | "@type": "SoftwareApplication",
206 | "identifier": "digest",
207 | "name": "digest",
208 | "provider": {
209 | "@id": "https://cran.r-project.org",
210 | "@type": "Organization",
211 | "name": "Comprehensive R Archive Network (CRAN)",
212 | "url": "https://cran.r-project.org"
213 | },
214 | "sameAs": "https://CRAN.R-project.org/package=digest"
215 | },
216 | "6": {
217 | "@type": "SoftwareApplication",
218 | "identifier": "R",
219 | "name": "R",
220 | "version": ">= 2.10"
221 | },
222 | "SystemRequirements": null
223 | },
224 | "fileSize": "1086.744KB"
225 | }
226 |
--------------------------------------------------------------------------------
/cran-comments.md:
--------------------------------------------------------------------------------
1 | ## R CMD check results
2 |
3 | 0 errors | 0 warnings | 1 note
4 |
5 | * This is a new release.
6 |
--------------------------------------------------------------------------------
/data-raw/ots_countries_colors.json:
--------------------------------------------------------------------------------
1 | [{"country_iso":"abw","continent_id":2,"country_color":"#D05555"},{"country_iso":"afg","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"ago","continent_id":1,"country_color":"#406662"},{"country_iso":"aia","continent_id":2,"country_color":"#D05555"},{"country_iso":"alb","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"all","country_color":"#BCD8AF"},{"country_iso":"and","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"ant","continent_id":2,"country_color":"#D05555"},{"country_iso":"are","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"arg","continent_id":2,"country_color":"#D05555"},{"country_iso":"arm","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"asm","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"ata","continent_id":3,"country_color":"#406662"},{"country_iso":"atf","continent_id":1,"country_color":"#406662"},{"country_iso":"atg","continent_id":2,"country_color":"#D05555"},{"country_iso":"aus","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"aut","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"aze","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"bdi","continent_id":1,"country_color":"#406662"},{"country_iso":"bel","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"ben","continent_id":1,"country_color":"#406662"},{"country_iso":"bes","continent_id":2,"country_color":"#D05555"},{"country_iso":"bfa","continent_id":1,"country_color":"#406662"},{"country_iso":"bgd","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"bgr","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"bhr","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"bhs","continent_id":2,"country_color":"#D05555"},{"country_iso":"bih","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"blm","continent_id":2,"country_color":"#D05555"},{"country_iso":"blr","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"blz","continent_id":2,"country_color":"#D05555"},{"country_iso":"bmu","continent_id":2,"country_color":"#D05555"},{"country_iso":"bol","continent_id":2,"country_color":"#D05555"},{"country_iso":"bra","continent_id":2,"country_color":"#D05555"},{"country_iso":"brb","continent_id":2,"country_color":"#D05555"},{"country_iso":"brn","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"btn","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"bvt","continent_id":2,"country_color":"#D05555"},{"country_iso":"bwa","continent_id":1,"country_color":"#406662"},{"country_iso":"c-af","continent_id":1,"country_color":"#406662"},{"country_iso":"c-am","continent_id":2,"country_color":"#D05555"},{"country_iso":"c-as","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"c-eu","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"c-oc","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"caf","continent_id":1,"country_color":"#406662"},{"country_iso":"can","continent_id":2,"country_color":"#D05555"},{"country_iso":"cck","continent_id":2,"country_color":"#D05555"},{"country_iso":"che","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"chl","continent_id":2,"country_color":"#D05555"},{"country_iso":"chn","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"civ","continent_id":1,"country_color":"#406662"},{"country_iso":"cmr","continent_id":1,"country_color":"#406662"},{"country_iso":"cod","continent_id":1,"country_color":"#406662"},{"country_iso":"cog","continent_id":1,"country_color":"#406662"},{"country_iso":"cok","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"col","continent_id":2,"country_color":"#D05555"},{"country_iso":"com","continent_id":1,"country_color":"#406662"},{"country_iso":"cpv","continent_id":1,"country_color":"#406662"},{"country_iso":"cri","continent_id":2,"country_color":"#D05555"},{"country_iso":"csk","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"cub","continent_id":2,"country_color":"#D05555"},{"country_iso":"cuw","continent_id":2,"country_color":"#D05555"},{"country_iso":"cxr","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"cym","continent_id":2,"country_color":"#D05555"},{"country_iso":"cyp","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"cze","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"ddr","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"deu","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"dji","continent_id":1,"country_color":"#406662"},{"country_iso":"dma","continent_id":2,"country_color":"#D05555"},{"country_iso":"dnk","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"dom","continent_id":2,"country_color":"#D05555"},{"country_iso":"dza","continent_id":1,"country_color":"#406662"},{"country_iso":"e-129","continent_id":2,"country_color":"#D05555"},{"country_iso":"e-221","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"e-290","continent_id":1,"country_color":"#406662"},{"country_iso":"e-471","continent_id":2,"country_color":"#D05555"},{"country_iso":"e-472","continent_id":1,"country_color":"#406662"},{"country_iso":"e-473","continent_id":2,"country_color":"#D05555"},{"country_iso":"e-490","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"e-492","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"e-527","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"e-536","country_color":"#BCD8AF"},{"country_iso":"e-568","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"e-577","continent_id":1,"country_color":"#406662"},{"country_iso":"e-636","continent_id":2,"country_color":"#D05555"},{"country_iso":"e-637","continent_id":2,"country_color":"#D05555"},{"country_iso":"e-697","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"e-80","continent_id":3,"country_color":"#406662"},{"country_iso":"e-837","country_color":"#BCD8AF"},{"country_iso":"e-838","country_color":"#BCD8AF"},{"country_iso":"e-839","country_color":"#BCD8AF"},{"country_iso":"e-849","continent_id":2,"country_color":"#D05555"},{"country_iso":"e-879","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"e-899","country_color":"#BCD8AF"},{"country_iso":"ecu","continent_id":2,"country_color":"#D05555"},{"country_iso":"egy","continent_id":1,"country_color":"#406662"},{"country_iso":"eri","continent_id":1,"country_color":"#406662"},{"country_iso":"esh","continent_id":1,"country_color":"#406662"},{"country_iso":"esp","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"est","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"eth","continent_id":1,"country_color":"#406662"},{"country_iso":"fin","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"fji","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"flk","continent_id":2,"country_color":"#D05555"},{"country_iso":"fra","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"fro","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"fsm","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"gab","continent_id":1,"country_color":"#406662"},{"country_iso":"gbr","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"geo","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"gha","continent_id":1,"country_color":"#406662"},{"country_iso":"gib","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"gin","continent_id":1,"country_color":"#406662"},{"country_iso":"glp","continent_id":2,"country_color":"#D05555"},{"country_iso":"gmb","continent_id":1,"country_color":"#406662"},{"country_iso":"gnb","continent_id":1,"country_color":"#406662"},{"country_iso":"gnq","continent_id":1,"country_color":"#406662"},{"country_iso":"grc","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"grd","continent_id":2,"country_color":"#D05555"},{"country_iso":"grl","continent_id":2,"country_color":"#D05555"},{"country_iso":"gtm","continent_id":2,"country_color":"#D05555"},{"country_iso":"guf","continent_id":2,"country_color":"#D05555"},{"country_iso":"gum","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"guy","continent_id":2,"country_color":"#D05555"},{"country_iso":"hkg","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"hmd","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"hnd","continent_id":2,"country_color":"#D05555"},{"country_iso":"hrv","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"hti","continent_id":2,"country_color":"#D05555"},{"country_iso":"hun","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"idn","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"ind","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"iot","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"irl","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"irn","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"irq","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"isl","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"isr","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"ita","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"jam","continent_id":2,"country_color":"#D05555"},{"country_iso":"jor","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"jpn","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"kaz","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"ken","continent_id":1,"country_color":"#406662"},{"country_iso":"kgz","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"khm","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"kir","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"kna","continent_id":2,"country_color":"#D05555"},{"country_iso":"kor","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"kwt","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"lao","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"lbn","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"lbr","continent_id":1,"country_color":"#406662"},{"country_iso":"lby","continent_id":1,"country_color":"#406662"},{"country_iso":"lca","continent_id":2,"country_color":"#D05555"},{"country_iso":"lka","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"lso","continent_id":1,"country_color":"#406662"},{"country_iso":"ltu","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"lux","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"lva","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"mac","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"mar","continent_id":1,"country_color":"#406662"},{"country_iso":"mda","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"mdg","continent_id":1,"country_color":"#406662"},{"country_iso":"mdv","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"mex","continent_id":2,"country_color":"#D05555"},{"country_iso":"mhl","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"mkd","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"mli","continent_id":1,"country_color":"#406662"},{"country_iso":"mlt","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"mmr","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"mne","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"mng","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"mnp","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"moz","continent_id":1,"country_color":"#406662"},{"country_iso":"mrt","continent_id":1,"country_color":"#406662"},{"country_iso":"msr","continent_id":2,"country_color":"#D05555"},{"country_iso":"mtq","continent_id":2,"country_color":"#D05555"},{"country_iso":"mus","continent_id":1,"country_color":"#406662"},{"country_iso":"mwi","continent_id":1,"country_color":"#406662"},{"country_iso":"mys","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"myt","continent_id":1,"country_color":"#406662"},{"country_iso":"nam","continent_id":1,"country_color":"#406662"},{"country_iso":"ncl","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"ner","continent_id":1,"country_color":"#406662"},{"country_iso":"nfk","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"nga","continent_id":1,"country_color":"#406662"},{"country_iso":"nic","continent_id":2,"country_color":"#D05555"},{"country_iso":"niu","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"nld","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"nor","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"npl","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"nru","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"nzl","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"omn","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"pak","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"pan","continent_id":2,"country_color":"#D05555"},{"country_iso":"pci","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"pcn","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"per","continent_id":2,"country_color":"#D05555"},{"country_iso":"phl","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"plw","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"png","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"pol","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"prk","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"prt","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"pry","continent_id":2,"country_color":"#D05555"},{"country_iso":"pse","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"pyf","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"qat","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"reu","continent_id":1,"country_color":"#406662"},{"country_iso":"rou","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"rus","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"rwa","continent_id":1,"country_color":"#406662"},{"country_iso":"sau","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"scg","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"sdn","continent_id":1,"country_color":"#406662"},{"country_iso":"sen","continent_id":1,"country_color":"#406662"},{"country_iso":"sgp","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"sgs","continent_id":2,"country_color":"#D05555"},{"country_iso":"shn","continent_id":1,"country_color":"#406662"},{"country_iso":"slb","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"sle","continent_id":1,"country_color":"#406662"},{"country_iso":"slv","continent_id":2,"country_color":"#D05555"},{"country_iso":"smr","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"som","continent_id":1,"country_color":"#406662"},{"country_iso":"spm","continent_id":2,"country_color":"#D05555"},{"country_iso":"srb","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"ssd","continent_id":1,"country_color":"#406662"},{"country_iso":"stp","continent_id":1,"country_color":"#406662"},{"country_iso":"sun","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"sur","continent_id":2,"country_color":"#D05555"},{"country_iso":"svk","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"svn","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"swe","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"swz","continent_id":1,"country_color":"#406662"},{"country_iso":"sxm","continent_id":2,"country_color":"#D05555"},{"country_iso":"syc","continent_id":1,"country_color":"#406662"},{"country_iso":"syr","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"tca","continent_id":2,"country_color":"#D05555"},{"country_iso":"tcd","continent_id":1,"country_color":"#406662"},{"country_iso":"tgo","continent_id":1,"country_color":"#406662"},{"country_iso":"tha","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"tjk","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"tkl","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"tkm","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"tls","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"ton","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"tto","continent_id":2,"country_color":"#D05555"},{"country_iso":"tun","continent_id":1,"country_color":"#406662"},{"country_iso":"tur","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"tuv","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"tza","continent_id":1,"country_color":"#406662"},{"country_iso":"uga","continent_id":1,"country_color":"#406662"},{"country_iso":"ukr","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"umi","continent_id":2,"country_color":"#D05555"},{"country_iso":"ury","continent_id":2,"country_color":"#D05555"},{"country_iso":"usa","continent_id":2,"country_color":"#D05555"},{"country_iso":"uzb","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"vat","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"vct","continent_id":2,"country_color":"#D05555"},{"country_iso":"ven","continent_id":2,"country_color":"#D05555"},{"country_iso":"vgb","continent_id":2,"country_color":"#D05555"},{"country_iso":"vir","continent_id":2,"country_color":"#D05555"},{"country_iso":"vnm","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"vut","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"wlf","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"wsm","continent_id":6,"country_color":"#DC8E7A"},{"country_iso":"yem","continent_id":4,"country_color":"#5C57D9"},{"country_iso":"ymd","continent_id":1,"country_color":"#406662"},{"country_iso":"yug","continent_id":5,"country_color":"#5C57D9"},{"country_iso":"zaf","continent_id":1,"country_color":"#406662"},{"country_iso":"zmb","continent_id":1,"country_color":"#406662"},{"country_iso":"zwe","continent_id":1,"country_color":"#406662"}]
--------------------------------------------------------------------------------
/data-raw/ots_sections.json:
--------------------------------------------------------------------------------
1 | [{"section_code":"01","section_fullname_english":"Live animals and animal products"},{"section_code":"02","section_fullname_english":"Vegetable products"},{"section_code":"03","section_fullname_english":"Animal or vegetable fats and oils and their cleavage products; prepared edible fats; animal or vegetble waxes"},{"section_code":"04","section_fullname_english":"Prepared foodstuffs, beverages, spirits and vinegar, tobacco and manufactured tobacco substitutes"},{"section_code":"05","section_fullname_english":"Mineral products"},{"section_code":"06","section_fullname_english":"Product of the chemicals or allied industries"},{"section_code":"07","section_fullname_english":"Plastics and articles thereof, rubber and articles thereof"},{"section_code":"08","section_fullname_english":"Raw hides and skins, leather, furskins and articles thereof, saddlery and harness, travel goods, handbags and similar containers, articles of animal gut (other than silk-worm gut)"},{"section_code":"09","section_fullname_english":"Wood and articles of wood, wood charcoal, cork and articles of cork, manufacturers of straw, of esparto or of other plaiting materials, basketwork and wickerwork"},{"section_code":"10","section_fullname_english":"Pulp of wood or of other fibrous cellulosic material, recovered (waste and scrap) paper or paperboard, paper and paperboard and articles thereof"},{"section_code":"11","section_fullname_english":"Textile and textile articles"},{"section_code":"12","section_fullname_english":"Footwear, headgear, umbrellas, sun umbrellas, walking-sticks, seat-sticks, whips, riding-crops and parts thereof, prepared feathers and articles made therewith, artificial flowers, articles of human hair."},{"section_code":"13","section_fullname_english":"Articles of stone, plaster, cement, asbestos, mica, or similar materials, ceramic products, glass and glassware"},{"section_code":"14","section_fullname_english":"Natural or cultured pearls, precious or semi-precious stones, precious metals, metal clad with precious metal, and articles thereof, imitation jewellery, coins"},{"section_code":"15","section_fullname_english":"Base metals and articles of base metal"},{"section_code":"16","section_fullname_english":"Machinery and mechanical appliances, electrical equipment, parts thereof, sound recorders and reproducers, television image and souch recorders and reproducers, and parts and accessories of such articles"},{"section_code":"17","section_fullname_english":"Vehicles, aircraft, vessels and associated transport equipment"},{"section_code":"18","section_fullname_english":"Optical, photographic, cinematographic, measuring, checking, precision, medical or surgical instruments and apparatus, clocks and watches, musical instruments, parts and accessories thereof"},{"section_code":"19","section_fullname_english":"Arms and ammunition, parts and accessories thereof"},{"section_code":"20","section_fullname_english":"Miscellaneous manufactured articles"},{"section_code":"21","section_fullname_english":"Works of art, collectors' pieces and antiques"},{"section_code":"99","section_fullname_english":"Unspecified"}]
--------------------------------------------------------------------------------
/data-raw/ots_sections_colors.json:
--------------------------------------------------------------------------------
1 | [{"section_code":"01","section_color":"#74c0e2"},{"section_code":"02","section_color":"#406662"},{"section_code":"03","section_color":"#549e95"},{"section_code":"04","section_color":"#8abdb6"},{"section_code":"05","section_color":"#bcd8af"},{"section_code":"06","section_color":"#a8c380"},{"section_code":"07","section_color":"#ede788"},{"section_code":"08","section_color":"#d6c650"},{"section_code":"09","section_color":"#dc8e7a"},{"section_code":"10","section_color":"#d05555"},{"section_code":"11","section_color":"#bf3251"},{"section_code":"12","section_color":"#872a41"},{"section_code":"13","section_color":"#993f7b"},{"section_code":"14","section_color":"#7454a6"},{"section_code":"15","section_color":"#a17cb0"},{"section_code":"16","section_color":"#d1a1bc"},{"section_code":"17","section_color":"#a1aafb"},{"section_code":"18","section_color":"#5c57d9"},{"section_code":"19","section_color":"#1c26b3"},{"section_code":"20","section_color":"#4d6fd0"},{"section_code":"21","section_color":"#7485aa"},{"section_code":"99","section_color":"#d3d3d3"}]
--------------------------------------------------------------------------------
/data-raw/ots_tables.csv:
--------------------------------------------------------------------------------
1 | table,description,source
2 | commodities,"Commodities metadata (HS codes, 6 digits long)",Based on UN Comtrade
3 | commodities_short,"Commodities metadata (HS codes, 4 digits long)",Based on UN Comtrade
4 | countries,Countries metadata,Based on UN Comtrade
5 | countries_colors,Countries colors,Open Trade Statistics
6 | sections,Sections metadata (HS codes),Based on UN Comtrade
7 | sections_colors,Sections colors (HS codes),Open Trade Statistics
8 | year_range,Minimum and maximum years with available data,Based on UN Comtrade
9 | yc,Commodity trade at aggregated level (Year and Commodity),Based on UN Comtrade
10 | yr,Reporter trade at aggregated level (Year and Reporter),Based on UN Comtrade
11 | yrc,"Reporter trade at commodity level (Year, Reporter and Commodity Code)",Based on UN Comtrade
12 | yrp,"Reporter-Partner trade at aggregated level (Year, Reporter and Partner)",Based on UN Comtrade
13 | yrpc,"Reporter-Partner trade at commodity level (Year, Reporter, Partner and Commodity Code)",Based on UN Comtrade
14 |
--------------------------------------------------------------------------------
/data/ots_commodities.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ropensci/tradestatistics/4c0b85989f0085f4eb4c16eaefab6214b7854b6b/data/ots_commodities.rda
--------------------------------------------------------------------------------
/data/ots_commodities_short.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ropensci/tradestatistics/4c0b85989f0085f4eb4c16eaefab6214b7854b6b/data/ots_commodities_short.rda
--------------------------------------------------------------------------------
/data/ots_countries.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ropensci/tradestatistics/4c0b85989f0085f4eb4c16eaefab6214b7854b6b/data/ots_countries.rda
--------------------------------------------------------------------------------
/data/ots_countries_colors.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ropensci/tradestatistics/4c0b85989f0085f4eb4c16eaefab6214b7854b6b/data/ots_countries_colors.rda
--------------------------------------------------------------------------------
/data/ots_gdp_deflator.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ropensci/tradestatistics/4c0b85989f0085f4eb4c16eaefab6214b7854b6b/data/ots_gdp_deflator.rda
--------------------------------------------------------------------------------
/data/ots_sections.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ropensci/tradestatistics/4c0b85989f0085f4eb4c16eaefab6214b7854b6b/data/ots_sections.rda
--------------------------------------------------------------------------------
/data/ots_sections_colors.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ropensci/tradestatistics/4c0b85989f0085f4eb4c16eaefab6214b7854b6b/data/ots_sections_colors.rda
--------------------------------------------------------------------------------
/data/ots_tables.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ropensci/tradestatistics/4c0b85989f0085f4eb4c16eaefab6214b7854b6b/data/ots_tables.rda
--------------------------------------------------------------------------------
/dev/config_attachment.yaml:
--------------------------------------------------------------------------------
1 | path.n: NAMESPACE
2 | path.d: DESCRIPTION
3 | dir.r: R
4 | dir.v: vignettes
5 | dir.t: tests
6 | extra.suggests: ~
7 | pkg_ignore: ~
8 | document: yes
9 | normalize: yes
10 | inside_rmd: no
11 | must.exist: yes
12 | check_if_suggests_is_installed: yes
13 |
--------------------------------------------------------------------------------
/dev/creating-datasets.R:
--------------------------------------------------------------------------------
1 | # Tables ----
2 |
3 | library(data.table)
4 | library(dplyr)
5 | library(jsonlite)
6 |
7 | base_url <- "http://localhost:4949/"
8 |
9 | tables_url <- paste0(base_url, "tables")
10 | tables_raw_file <- "data-raw/ots_tables.csv"
11 | tables_tidy_file <- "data/ots_tables.rda"
12 |
13 | if (!file.exists(tables_raw_file)) {
14 | download.file(tables_url, tables_raw_file)
15 | }
16 |
17 | if (!file.exists(tables_tidy_file)) {
18 | ots_tables <- fread(tables_raw_file) %>%
19 | mutate_if(is.character, function(x) { iconv(x, to = "ASCII//TRANSLIT")})
20 | save(ots_tables, file = tables_tidy_file, version = 2)
21 | }
22 |
23 | # Country codes ----
24 |
25 | countries_url <- paste0(base_url, "countries")
26 | countries_raw_file <- "data-raw/ots_countries.json"
27 | countries_tidy_file <- "data/ots_countries.rda"
28 |
29 | if (!file.exists(countries_raw_file)) {
30 | download.file(countries_url, countries_raw_file)
31 | }
32 |
33 | if (!file.exists(countries_tidy_file)) {
34 | ots_countries <- fromJSON(countries_raw_file) %>%
35 | mutate_if(is.character, function(x) { iconv(x, to = "ASCII//TRANSLIT")}) %>%
36 | mutate_if(is.numeric, as.integer) %>%
37 | as.data.table()
38 |
39 | save(ots_countries, file = countries_tidy_file, version = 2)
40 | }
41 |
42 | # Commodity codes ----
43 |
44 | commodities_url <- paste0(base_url, "commodities")
45 | commodities_raw_file <- "data-raw/ots_commodities.json"
46 | commodities_tidy_file <- "data/ots_commodities.rda"
47 |
48 | if (!file.exists(commodities_raw_file)) {
49 | download.file(commodities_url, commodities_raw_file)
50 | }
51 |
52 | if (!file.exists(commodities_tidy_file)) {
53 | ots_commodities <- fromJSON(commodities_raw_file) %>%
54 | mutate_if(is.character, function(x) { iconv(x, to = "ASCII//TRANSLIT")}) %>%
55 | as.data.table()
56 |
57 | save(ots_commodities, file = commodities_tidy_file, version = 2, compress = "xz")
58 | }
59 |
60 | # Sections codes ----
61 |
62 | sections_url <- paste0(base_url, "sections")
63 | sections_raw_file <- "data-raw/ots_sections.json"
64 | sections_tidy_file <- "data/ots_sections.rda"
65 |
66 | if (!file.exists(sections_raw_file)) {
67 | download.file(sections_url, sections_raw_file)
68 | }
69 |
70 | if (!file.exists(sections_tidy_file)) {
71 | ots_sections <- fromJSON(sections_raw_file) %>%
72 | mutate_if(is.character, function(x) { iconv(x, to = "ASCII//TRANSLIT")}) %>%
73 | as.data.table()
74 |
75 | save(ots_sections, file = sections_tidy_file, version = 2)
76 | }
77 |
78 | # Shorter commodity codes ----
79 |
80 | commodities_short_url <- paste0(base_url, "commodities_short")
81 | commodities_short_raw_file <- "data-raw/ots_commodities_short.json"
82 | commodities_short_tidy_file <- "data/ots_commodities_short.rda"
83 |
84 | if (!file.exists(commodities_short_raw_file)) {
85 | download.file(commodities_short_url, commodities_short_raw_file)
86 | }
87 |
88 | if (!file.exists(commodities_short_tidy_file)) {
89 | ots_commodities_short <- fromJSON(commodities_short_raw_file) %>%
90 | mutate_if(is.character, function(x) { iconv(x, to = "ASCII//TRANSLIT")}) %>%
91 | as.data.table()
92 |
93 | save(ots_commodities_short, file = commodities_short_tidy_file, version = 2, compress = "xz")
94 | }
95 |
96 | # GDP deflator ----
97 |
98 | # Source
99 | # https://data.worldbank.org/indicator/NY.GDP.DEFL.KD.ZG
100 |
101 | gdp_deflator_rds <- "../tradestatistics-database-postgresql/gdp/gdp_deflator.rds"
102 | gdp_deflator_tidy_file <- "data/ots_gdp_deflator.rda"
103 |
104 | if (!file.exists(gdp_deflator_tidy_file)) {
105 | ots_gdp_deflator <- readRDS(gdp_deflator_rds)
106 | ots_gdp_deflator <- ots_gdp_deflator %>%
107 | mutate(year_from = as.integer(year_from), year_to = as.integer(year_to)) %>%
108 | as.data.table()
109 |
110 | save(ots_gdp_deflator, file = gdp_deflator_tidy_file, version = 2, compress = "xz")
111 | }
112 |
113 | # Colors ----
114 |
115 | sections_colors_url <- paste0(base_url, "sections_colors")
116 | sections_colors_raw_file <- "data-raw/ots_sections_colors.json"
117 | sections_colors_tidy_file <- "data/ots_sections_colors.rda"
118 |
119 | if (!file.exists(sections_colors_raw_file)) {
120 | download.file(sections_colors_url, sections_colors_raw_file)
121 | }
122 |
123 | if (!file.exists(sections_colors_tidy_file)) {
124 | ots_sections_colors <- fromJSON(sections_colors_raw_file) %>%
125 | mutate_if(is.character, function(x) { iconv(x, to = "ASCII//TRANSLIT")}) %>%
126 | as.data.table()
127 |
128 | save(ots_sections_colors, file = sections_colors_tidy_file, version = 2)
129 | }
130 |
131 | countries_colors_url <- paste0(base_url, "countries_colors")
132 | countries_colors_raw_file <- "data-raw/ots_countries_colors.json"
133 | countries_colors_tidy_file <- "data/ots_countries_colors.rda"
134 |
135 | if (!file.exists(countries_colors_raw_file)) {
136 | download.file(countries_colors_url, countries_colors_raw_file)
137 | }
138 |
139 | if (!file.exists(countries_colors_tidy_file)) {
140 | ots_countries_colors <- fromJSON(countries_colors_raw_file) %>%
141 | mutate_if(is.character, function(x) { iconv(x, to = "ASCII//TRANSLIT")}) %>%
142 | as.data.table()
143 |
144 | save(ots_countries_colors, file = countries_colors_tidy_file, version = 2)
145 | }
146 |
--------------------------------------------------------------------------------
/inst/references.bib:
--------------------------------------------------------------------------------
1 | @article {Peng2011,
2 | author = {Peng, Roger D.},
3 | title = {Reproducible Research in Computational Science},
4 | volume = {334},
5 | number = {6060},
6 | pages = {1226--1227},
7 | year = {2011},
8 | doi = {10.1126/science.1213847},
9 | publisher = {American Association for the Advancement of Science},
10 | abstract = {Computational science has led to exciting new developments, but the nature of the work has exposed limitations in our ability to evaluate published findings. Reproducibility has the potential to serve as a minimum standard for judging scientific claims when full independent replication of a study is not possible.},
11 | issn = {0036-8075},
12 | URL = {http://science.sciencemag.org/content/334/6060/1226},
13 | eprint = {http://science.sciencemag.org/content/334/6060/1226.full.pdf},
14 | journal = {Science}
15 | }
16 |
17 | @misc{uncomtrade,
18 | title = {UN Comtrade Database},
19 | url = {https://comtrade.un.org/data/},
20 | author = {{UN Comtrade Database}},
21 | publisher = {United Nations Publications},
22 | year = {2019},
23 | month = {Aug},
24 | note = {Accessed: Aug 30, 2019}
25 | }
26 |
27 | @misc{opentradestatistics,
28 | title = {Open Trade Statistics},
29 | url = {https://tradestatistics.io/},
30 | author = {{Open Trade Statistics}},
31 | publisher = {Open Trade Statistics},
32 | year = {2024},
33 | month = {Aug},
34 | note = {Accessed: Aug 21, 2024}
35 | }
36 |
37 | @Manual{plumber,
38 | title = {plumber: An API Generator for R},
39 | author = {Barret Schloerke and Jeff Allen},
40 | year = {2024},
41 | note = {R package version 1.2.2},
42 | url = {https://CRAN.R-project.org/package=plumber}
43 | }
44 |
45 | @misc{postgresql,
46 | title = {PostgreSQL: The World's Most Advanced Open Source Relational Database},
47 | url = {https://www.postgresql.org/},
48 | author = {Michael Stonebraker},
49 | publisher = {PostgreSQL Global Development Groups},
50 | year = {2024},
51 | month = {Aug},
52 | note = {Accessed: Aug 21, 2024}
53 | }
54 |
55 | @Manual{shiny,
56 | title = {shiny: Web Application Framework for R},
57 | author = {Winston Chang and Joe Cheng and JJ Allaire and Yihui Xie and Jonathan McPherson},
58 | year = {2019},
59 | note = {R package version 1.3.2},
60 | url = {https://CRAN.R-project.org/package=shiny}
61 | }
62 |
63 | @Manual{shinydashboard,
64 | title = {shinydashboard: Create Dashboards with 'Shiny'},
65 | author = {Winston Chang and Barbara {Borges Ribeiro}},
66 | year = {2024},
67 | note = {R package version 0.7.2},
68 | url = {http://rstudio.github.io/shinydashboard/}
69 | }
70 |
71 | @Manual{base,
72 | title = {R: A Language and Environment for Statistical Computing},
73 | author = {{R Core Team}},
74 | organization = {R Foundation for Statistical Computing},
75 | address = {Vienna, Austria},
76 | year = {2024},
77 | url = {https://www.R-project.org/}
78 | }
79 |
80 | @Article{tidyverse,
81 | title = {Welcome to the {tidyverse}},
82 | author = {Hadley Wickham and Mara Averick and Jennifer Bryan and Winston Chang and Lucy D'Agostino McGowan and Romain François and Garrett Grolemund and Alex Hayes and Lionel Henry and Jim Hester and Max Kuhn and Thomas Lin Pedersen and Evan Miller and Stephan Milton Bache and Kirill Müller and Jeroen Ooms and David Robinson and Dana Paige Seidel and Vitalie Spinu and Kohske Takahashi and Davis Vaughan and Claus Wilke and Kara Woo and Hiroaki Yutani},
83 | year = {2019},
84 | journal = {Journal of Open Source Software},
85 | volume = {4},
86 | number = {43},
87 | pages = {1686},
88 | doi = {10.21105/joss.01686}
89 | }
90 |
--------------------------------------------------------------------------------
/man/ots_cache.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/ots_cache.R
3 | \name{ots_cache}
4 | \alias{ots_cache}
5 | \title{Caching wrapper to reduce API calls (internal)}
6 | \usage{
7 | ots_cache(use_cache, file, ...)
8 | }
9 | \arguments{
10 | \item{use_cache}{Logical to save and load from cache. If \code{TRUE}, the results will be cached in memory
11 | if \code{file} is \code{NULL} or on disk if `file` is not \code{NULL}.}
12 |
13 | \item{file}{Character with the full file path to save the data.}
14 |
15 | \item{...}{Additional parameters inherited from \code{ots_create_tidy_data()}.}
16 | }
17 | \description{
18 | Eases saving the data downloaded from \code{api.tradestatistics.io}
19 | and prevents \code{ots_read_from_api()} from downloading the same twice.
20 | }
21 | \keyword{internal}
22 |
--------------------------------------------------------------------------------
/man/ots_commodities.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/tradestatistics-package.R
3 | \docType{data}
4 | \name{ots_commodities}
5 | \alias{ots_commodities}
6 | \title{OTS Commodities}
7 | \format{
8 | A data frame with 5,302 observations on the following 4 variables
9 | \describe{
10 | \item{\code{commodity_code}}{HS six digits commodity code (e.g. 010110)}
11 | \item{\code{commodity_code_short}}{HS four digits commodity code (e.g. 0101)}
12 | \item{\code{commodity_fullname_english}}{HS six digits commodity name (e.g. 'Horses, asses, mules and hinnies; live, pure-bred breeding animals')}
13 | \item{\code{section_code}}{HS section code (e.g. '01')}
14 | }
15 | }
16 | \source{
17 | Open Trade Statistics
18 | }
19 | \usage{
20 | ots_commodities
21 | }
22 | \description{
23 | Official commodity names from the Harmonized System rev 2012
24 | (HS12, six digits detail).
25 | }
26 | \keyword{datasets}
27 |
--------------------------------------------------------------------------------
/man/ots_commodities_short.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/tradestatistics-package.R
3 | \docType{data}
4 | \name{ots_commodities_short}
5 | \alias{ots_commodities_short}
6 | \title{OTS Commodities Short}
7 | \format{
8 | A data frame with 1,225 observations on the following 2 variables
9 | \describe{
10 | \item{\code{commodity_code}}{HS four digits commodity code (e.g. 0101)}
11 | \item{\code{commodity_fullname_english}}{HS four digits commodity names (e.g. 'Horses, asses, mules and hinnies; live')}
12 | }
13 | }
14 | \source{
15 | Open Trade Statistics
16 | }
17 | \usage{
18 | ots_commodities_short
19 | }
20 | \description{
21 | Official commodity names from the Harmonized System rev 2012
22 | (HS12, four digits detail).
23 | }
24 | \keyword{datasets}
25 |
--------------------------------------------------------------------------------
/man/ots_commodity_code.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/ots_strings_processing.R
3 | \name{ots_commodity_code}
4 | \alias{ots_commodity_code}
5 | \title{String matching of official commodity/section names and Harmonized System (HS) codes
6 | according to the United Nations nomenclature}
7 | \usage{
8 | ots_commodity_code(commodity = NULL, section = NULL)
9 | }
10 | \arguments{
11 | \item{commodity}{A text string such as "Animals", "COPPER" or "fruits".}
12 |
13 | \item{section}{A text string such as "meat", "FISH" or "Dairy".}
14 | }
15 | \value{
16 | A tibble with all possible matches (no uppercase distinction)
17 | showing the commodity name and commodity code
18 | }
19 | \description{
20 | Takes a text string and searches within the
21 | package data for all matching commodity codes in the context of valid API
22 | commodity codes.
23 | }
24 | \examples{
25 | ots_commodity_code(commodity = "ANIMALS ")
26 | ots_commodity_code(section = " fish")
27 | ots_commodity_code(commodity = "Milk", section = "Dairy")
28 | }
29 | \keyword{functions}
30 |
--------------------------------------------------------------------------------
/man/ots_countries.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/tradestatistics-package.R
3 | \docType{data}
4 | \name{ots_countries}
5 | \alias{ots_countries}
6 | \title{OTS Countries}
7 | \format{
8 | A data frame with 275 observations on the following 5 variables
9 | \describe{
10 | \item{\code{country_iso}}{ISO-3 code of the country (e.g. "deu" means Germany)}
11 | \item{\code{country_name_english}}{Country name (e.g. Germany)}
12 | \item{\code{country_fullname_english}}{Country name with indications (e.g. Germany as "Germany (former Federal Republic of Germany until 1990)")}
13 | \item{\code{continent_name_english}}{Continent where the country belongs to (e.g., Europe)}
14 | \item{\code{continent_id}}{Numeric id of the continent where the country belongs to (e.g., 5)}
15 | }
16 | }
17 | \source{
18 | Open Trade Statistics
19 | }
20 | \usage{
21 | ots_countries
22 | }
23 | \description{
24 | Official country names, ISO-3 codes, continent and EU membership.
25 | }
26 | \keyword{datasets}
27 |
--------------------------------------------------------------------------------
/man/ots_countries_colors.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/tradestatistics-package.R
3 | \docType{data}
4 | \name{ots_countries_colors}
5 | \alias{ots_countries_colors}
6 | \title{OTS Countries Colors}
7 | \format{
8 | A data frame with 275 rows and 3 variables
9 | \describe{
10 | \item{\code{country_iso}}{ISO code of the country (e.g. "chl" means Chile)}
11 | \item{\code{continent_id}}{Numeric id of the continent}
12 | \item{\code{country_color}}{Country hex color (e.g. '#D05555')}
13 | }
14 | }
15 | \source{
16 | Open Trade Statistics
17 | }
18 | \usage{
19 | ots_countries_colors
20 | }
21 | \description{
22 | Unofficial colors to ease visualization for countries.
23 | }
24 | \keyword{datasets}
25 |
--------------------------------------------------------------------------------
/man/ots_country_code.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/ots_strings_processing.R
3 | \name{ots_country_code}
4 | \alias{ots_country_code}
5 | \title{String matching of official country names and ISO-3 codes according to
6 | the United Nations nomenclature}
7 | \usage{
8 | ots_country_code(countryname = NULL)
9 | }
10 | \arguments{
11 | \item{countryname}{A text string such as "Chile", "CHILE" or "CHL".}
12 | }
13 | \value{
14 | A single character if there is a exact match (e.g.
15 | \code{ots_country_code("Chile")}) or a tibble in case of multiple matches
16 | (e.g. \code{ots_country_code("Germany")})
17 | }
18 | \description{
19 | Takes a text string and searches within the
20 | package data for a country code in the context of valid API country codes.
21 | }
22 | \examples{
23 | ots_country_code("Chile ")
24 | ots_country_code("america")
25 | ots_country_code("UNITED STATES")
26 | ots_country_code(" united_")
27 | }
28 | \keyword{functions}
29 |
--------------------------------------------------------------------------------
/man/ots_create_tidy_data.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/ots_create_tidy_data.R
3 | \name{ots_create_tidy_data}
4 | \alias{ots_create_tidy_data}
5 | \title{Downloads and processes the data from the API to return a human-readable tibble}
6 | \usage{
7 | ots_create_tidy_data(
8 | years = 2020,
9 | reporters = "all",
10 | partners = "all",
11 | commodities = "all",
12 | sections = "all",
13 | table = "yr",
14 | max_attempts = 5,
15 | use_cache = FALSE,
16 | file = NULL
17 | )
18 | }
19 | \arguments{
20 | \item{years}{Year contained within the years specified in
21 | api.tradestatistics.io/year_range (e.g. \code{c(2002,2004)}, \code{c(2002:2004)} or \code{2002}).
22 | Default set to \code{2019}.}
23 |
24 | \item{reporters}{ISO code for reporter country (e.g. \code{"chl"}, \code{"Chile"} or
25 | \code{c("chl", "Peru")}). Default set to \code{"all"}.}
26 |
27 | \item{partners}{ISO code for partner country (e.g. \code{"chl"}, \code{"Chile"} or
28 | \code{c("chl", "Peru")}). Default set to \code{"all"}.}
29 |
30 | \item{commodities}{HS commodity codes (e.g. \code{"0101"}, \code{"01"} or search
31 | matches for \code{"apple"})
32 | to filter commodities. Default set to \code{"all"}.}
33 |
34 | \item{sections}{HS section codes (e.g. \code{"01"}). Default set to \code{"all"}.}
35 |
36 | \item{table}{Character string to select the table to obtain the data.
37 | Default set to \code{yr} (Year - Reporter).
38 | Run \code{ots_tables} in case of doubt.}
39 |
40 | \item{max_attempts}{How many times to try to download data in case the
41 | API or the internet connection fails when obtaining data. Default set
42 | to \code{5}.}
43 |
44 | \item{use_cache}{Logical to save and load from cache. If \code{TRUE}, the results will be cached in memory
45 | if \code{file} is \code{NULL} or on disk if `file` is not \code{NULL}. Default set to \code{FALSE}.}
46 |
47 | \item{file}{Optional character with the full file path to save the data. Default set to \code{NULL}.}
48 | }
49 | \value{
50 | A tibble that describes bilateral trade metrics (imports,
51 | exports, trade balance and relevant metrics
52 | such as exports growth w/r to last year) between a \code{reporter}
53 | and \code{partner} country.
54 | }
55 | \description{
56 | Accesses \code{api.tradestatistics.io} and
57 | performs different API calls to transform and return tidy data.
58 | }
59 | \examples{
60 | \dontrun{
61 | # The next examples can take more than 5 seconds to compute,
62 | # so these are just shown without evaluation according to CRAN rules
63 |
64 | # Run `ots_countries` to display the full table of countries
65 | # Run `ots_commodities` to display the full table of commodities
66 |
67 | # What does Chile export to China? (2002)
68 | ots_create_tidy_data(years = 2002, reporters = "chl", partners = "chn")
69 |
70 | # What can we say about Horses export in Chile and the World? (2002)
71 | ots_create_tidy_data(years = 2002, commodities = "010110", table = "yc")
72 | ots_create_tidy_data(years = 2002, reporters = "chl", commodities = "010110", table = "yrc")
73 |
74 | # What can we say about the different types of apples exported by Chile? (2002)
75 | ots_create_tidy_data(years = 2002, reporters = "chl", commodities = "apple", table = "yrc")
76 | }
77 | }
78 | \keyword{functions}
79 |
--------------------------------------------------------------------------------
/man/ots_create_tidy_data_memoised.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/ots_create_tidy_data.R
3 | \name{ots_create_tidy_data_memoised}
4 | \alias{ots_create_tidy_data_memoised}
5 | \title{Downloads and processes the data from the API to return a human-readable tibble (memoised, internal)}
6 | \usage{
7 | ots_create_tidy_data_memoised(
8 | years = 2018,
9 | reporters = "usa",
10 | partners = "all",
11 | commodities = "all",
12 | sections = "all",
13 | table = "yr",
14 | max_attempts = 5
15 | )
16 | }
17 | \description{
18 | A composition of \code{ots_create_tidy_data_unmemoised()} and \code{memoise()} for caching the output
19 | }
20 | \keyword{internal}
21 |
--------------------------------------------------------------------------------
/man/ots_create_tidy_data_unmemoised.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/ots_create_tidy_data.R
3 | \name{ots_create_tidy_data_unmemoised}
4 | \alias{ots_create_tidy_data_unmemoised}
5 | \title{Downloads and processes the data from the API to return a human-readable tibble (unmemoised, internal)}
6 | \usage{
7 | ots_create_tidy_data_unmemoised(
8 | years = 2018,
9 | reporters = "usa",
10 | partners = "all",
11 | commodities = "all",
12 | sections = "all",
13 | table = "yr",
14 | max_attempts = 5
15 | )
16 | }
17 | \description{
18 | A separation of \code{ots_create_tidy_data()} for making caching optional.
19 | }
20 | \keyword{internal}
21 |
--------------------------------------------------------------------------------
/man/ots_gdp_deflator.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/tradestatistics-package.R
3 | \docType{data}
4 | \name{ots_gdp_deflator}
5 | \alias{ots_gdp_deflator}
6 | \title{GDP Deflator}
7 | \format{
8 | A data frame with 8,010 observations on the following 4 variables
9 | \describe{
10 | \item{\code{year_from}}{Integer values in the range 1980-2020}
11 | \item{\code{year_to}}{Integer values in the range 1981-2021}
12 | \item{\code{country_iso}}{ISO code of the country (e.g. "chl" means Chile)}
13 | \item{\code{gdp_deflator}}{Numeric value expressed as one plus 1-year deflator}
14 | }
15 | }
16 | \source{
17 | Open Trade Statistics
18 | }
19 | \usage{
20 | ots_gdp_deflator
21 | }
22 | \description{
23 | Year to year GDP deflator some of the countries in the OTS database. For
24 | countries not available in the World Bank database, rows labelled as "wld"
25 | are provided, which were computed as the weighted median for each year using
26 | the GDP of listed countries for each year expressed as constant dollars of
27 | the year 2010.
28 | }
29 | \keyword{datasets}
30 |
--------------------------------------------------------------------------------
/man/ots_gdp_deflator_adjustment.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/ots_gdp_deflator_adjustment.R
3 | \name{ots_gdp_deflator_adjustment}
4 | \alias{ots_gdp_deflator_adjustment}
5 | \title{Expresses tidy data from the API in dollars of a reference year}
6 | \usage{
7 | ots_gdp_deflator_adjustment(trade_data = NULL, reference_year = NULL)
8 | }
9 | \arguments{
10 | \item{trade_data}{A tibble obtained by using ots_create_tidy_data.
11 | Default set to \code{NULL}.}
12 |
13 | \item{reference_year}{Year contained within the years specified in
14 | api.tradestatistics.io/year_range (e.g. \code{2010}).
15 | Default set to \code{NULL}.}
16 | }
17 | \description{
18 | Uses GDP deflator records from The World Bank to
19 | convert trade records and express them in dollars of the same year. The
20 | records are internally subsetted to World's values, because country specific
21 | levels would largely re-scale observations for reporters that reflect
22 | unstable macroeconomic policies.
23 | }
24 | \examples{
25 | \dontrun{
26 | # The next example can take more than 5 seconds to compute,
27 | # so this is shown without evaluation according to CRAN rules
28 |
29 | # Convert dollars of 2010 to dollars of 2000
30 | d <- ots_create_tidy_data(years = 2010, reporters = "chl", partners = "chn")
31 | ots_gdp_deflator_adjustment(trade_data = d, reference_year = 2000)
32 | }
33 | }
34 | \keyword{functions}
35 |
--------------------------------------------------------------------------------
/man/ots_read_from_api.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/ots_read_from_api.R
3 | \name{ots_read_from_api}
4 | \alias{ots_read_from_api}
5 | \title{Reads data from the API (internal function)}
6 | \usage{
7 | ots_read_from_api(
8 | year = NULL,
9 | reporter_iso = NULL,
10 | partner_iso = NULL,
11 | commodity_code = "all",
12 | section_code = "all",
13 | table = "yr",
14 | max_attempts = 5
15 | )
16 | }
17 | \description{
18 | Accesses \code{api.tradestatistics.io} and
19 | performs different API calls to return \code{data.frames} by reading
20 | \code{JSON} data. The parameters here are passed from
21 | \code{ots_create_tidy_data}.
22 | }
23 | \keyword{internal}
24 |
--------------------------------------------------------------------------------
/man/ots_sections.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/tradestatistics-package.R
3 | \docType{data}
4 | \name{ots_sections}
5 | \alias{ots_sections}
6 | \title{OTS Sections}
7 | \format{
8 | A data frame with 22 rows and 2 variables
9 | \describe{
10 | \item{\code{section_code}}{HS section code (e.g. '01')}
11 | \item{\code{section_fullname_english}}{HS section name (e.g. 'Live animals and animal products')}
12 | }
13 | }
14 | \source{
15 | Adapted from UN COMTRADE
16 | }
17 | \usage{
18 | ots_sections
19 | }
20 | \description{
21 | Official section names from the Harmonized System rev 2012 (HS12).
22 | }
23 | \keyword{datasets}
24 |
--------------------------------------------------------------------------------
/man/ots_sections_colors.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/tradestatistics-package.R
3 | \docType{data}
4 | \name{ots_sections_colors}
5 | \alias{ots_sections_colors}
6 | \title{OTS Sections Colors}
7 | \format{
8 | A data frame with 22 rows and 2 variables
9 | \describe{
10 | \item{\code{section_code}}{HS section code (e.g. '01')}
11 | \item{\code{section_color}}{HS section color (e.g. '#74c0e2')}
12 | }
13 | }
14 | \source{
15 | Open Trade Statistics
16 | }
17 | \usage{
18 | ots_sections_colors
19 | }
20 | \description{
21 | Unofficial colors to ease visualization for the sections in
22 | the Harmonized System rev 2012 (HS12).
23 | }
24 | \keyword{datasets}
25 |
--------------------------------------------------------------------------------
/man/ots_tables.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/tradestatistics-package.R
3 | \docType{data}
4 | \name{ots_tables}
5 | \alias{ots_tables}
6 | \title{OTS Tables}
7 | \format{
8 | A data frame with 12 rows and 3 variables
9 | \describe{
10 | \item{\code{table}}{Table name}
11 | \item{\code{description}}{Description of table contents}
12 | \item{\code{source}}{Source for the data (OTS tables are processed after UN Comtrade raw data)}
13 | }
14 | }
15 | \source{
16 | Open Trade Statistics
17 | }
18 | \usage{
19 | ots_tables
20 | }
21 | \description{
22 | Existing API tables with both description and source.
23 | }
24 | \keyword{datasets}
25 |
--------------------------------------------------------------------------------
/man/tradestatistics-package.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/tradestatistics-package.R
3 | \docType{package}
4 | \name{tradestatistics-package}
5 | \alias{tradestatistics}
6 | \alias{tradestatistics-package}
7 | \title{tradestatistics: Open Trade Statistics API Wrapper and Utility Program}
8 | \description{
9 | Access 'Open Trade Statistics' API from R to download international trade data.
10 | }
11 | \seealso{
12 | Useful links:
13 | \itemize{
14 | \item \url{https://docs.ropensci.org/tradestatistics/}
15 | \item Report bugs at \url{https://github.com/ropensci/tradestatistics/issues/}
16 | }
17 |
18 | }
19 | \author{
20 | \strong{Maintainer}: Mauricio Vargas \email{mavargas11@uc.cl} (\href{https://orcid.org/0000-0003-1017-7574}{ORCID}) [copyright holder]
21 |
22 | Other contributors:
23 | \itemize{
24 | \item Joshua Kunst (contributed to different parts of the pre-release code) [contributor]
25 | \item Alexey Kravchenko (reviewed 2021 version of the API) [contributor]
26 | \item Emma Mendelsohn (updated the functions to take available years from the API instead of hardcoded values) [contributor]
27 | \item Daniela de los Santos (proposed improvements to default parameters) [contributor]
28 | \item Emily Riederer (reviewed the package for rOpenSci, see https://github.com/ropensci/onboarding/issues/274) [reviewer]
29 | \item Mark Padgham (reviewed the package for rOpenSci, see https://github.com/ropensci/onboarding/issues/274) [reviewer]
30 | \item Amanda Dobbyn (reviewed a previous package that evolved into the current package for rOpenSci, see https://github.com/ropensci/onboarding/issues/217) [reviewer]
31 | \item Jorge Cimentada (reviewed a previous package that evolved into the current package for rOpenSci, see https://github.com/ropensci/onboarding/issues/217) [reviewer]
32 | \item UN Comtrade [data contributor]
33 | \item The World Bank [data contributor]
34 | }
35 |
36 | }
37 | \keyword{internal}
38 |
--------------------------------------------------------------------------------
/paper/paper.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ropensci/tradestatistics/4c0b85989f0085f4eb4c16eaefab6214b7854b6b/paper/paper.pdf
--------------------------------------------------------------------------------
/paper/paper.rmd:
--------------------------------------------------------------------------------
1 | ---
2 | title:"The Open Trade Statistics Database: Advancing Access to International Trade Data through Open Source Solutions"
3 | date: 2024-08-21
4 | author1: "Mauricio Vargas Sepúlveda (ORCID 0000-0003-1017-7574)"
5 | email1: m.sepulveda@mail.utoronto.ca
6 | affiliation11: Department of Political Science, University of Toronto
7 | affiliation12: Munk School of Global Affairs and Public Policy, University of Toronto
8 | output:
9 | pdf_document:
10 | latex_engine: pdflatex
11 | template: "template.tex"
12 | keep_tex: true
13 | bibliography: ../inst/references.bib
14 | csl: chicago.csl
15 | fontsize: 12pt
16 | linespacing: 1.5
17 | margin: 1
18 | paper: letterpaper
19 | customfonts: false
20 | sansserif: false
21 | amsthm: false
22 | outline: true
23 | ---
24 |
25 | # Abstract
26 |
27 | The Open Trade Statistics (OTS) initiative was developed to democratize access
28 | to international trade data by providing downloadable SQL database dumps, a
29 | public API, a dashboard, and an R package for data retrieval. This project was
30 | born out of the recognition that many academic institutions in Latin America
31 | lack access to academic subscriptions and comprehensive datasets like the
32 | United Nations Commodity Trade Statistics Database (UN COMTRADE). The OTS
33 | project not only offers a solution to this problem regarding international trade
34 | data but also emphasizes the importance of reproducibility in data processing.
35 | Through the use of open-source tools, the project ensures that its datasets are
36 | accessible, flexible, and easy to use for research and analysis.
37 |
38 | # Introduction
39 |
40 | Access to reliable and comprehensive international trade data is critical for
41 | researchers, policymakers, and businesses. However, many institutions,
42 | particularly in Latin America, face challenges in accessing such data due to
43 | financial or institutional limitations. The Open Trade Statistics (OTS) project
44 | was created to address this gap by providing an alternative to the UN COMTRADE
45 | database. OTS offers curated datasets that are accessible to anyone, excluding
46 | commercial use, thereby lowering the barrier to working with international
47 | economic trade data.
48 |
49 | # Methodology
50 |
51 | The development of OTS involved several key steps. The project began with an
52 | in-depth analysis of existing trade data APIs to identify opportunities for
53 | creating a more flexible and user-friendly tool. The project then proceeded
54 | with cleaning @uncomtrade raw data with R and the Tidyverse [@base; @tidyverse],
55 | and then organizing it into a PostgreSQL database [@postgresql]. In order to
56 | ensure that the project was manageable and that all processes were reproducible
57 | and sustainable, the code was divided organizing into small GitHub repositories
58 | with clear documentation.
59 |
60 | # The Role of Open Source
61 |
62 | Central to the success of OTS is its reliance on open-source software. The project is built on a foundation of Ubuntu, PostgreSQL, and R, with a range of R packages used for data cleaning, database management, and visualization. These include `data.table`, `jsonlite`, `dplyr`, `tidyr`, `stringr`, and `janitor`, among others. The API was developed using the Plumber package in R, and the entire web service is hosted on a secure, open-source stack including nginx and Let’s Encrypt.
63 |
64 | #### Reproducibility and Community Contribution
65 | A critical aspect of the OTS project is its focus on reproducibility. By organizing the code and documenting every step, the project ensures that future users can easily understand and replicate the processes involved. The project also benefited significantly from the contributions of the rOpenSci community, whose thorough reviews and feedback led to substantial improvements in the API and the overall functionality of the project.
66 |
67 | #### Results and Discussion
68 | The OTS API and R package provide an efficient and user-friendly solution for retrieving international trade data. By comparing OTS with other existing tools, it is evident that OTS offers a more streamlined and accessible approach to data retrieval. For example, using the OTS API, users can easily obtain and manipulate trade data with just a few lines of R code. This simplicity, combined with the comprehensive documentation and examples provided, makes OTS a valuable resource for researchers and analysts.
69 |
70 | #### Conclusion
71 | The Open Trade Statistics project represents a significant advancement in the accessibility of international trade data. By leveraging open-source tools and focusing on reproducibility, OTS provides a sustainable and flexible solution for accessing and analyzing trade data. This project not only addresses the immediate needs of institutions lacking access to comprehensive datasets but also sets a precedent for future open-source initiatives in the field of economic data analysis.
72 |
73 | #### References
74 | 1. Vargas Sepúlveda, M. (2019). Open Trade Statistics. Retrieved from [rOpenSci](https://ropensci.org/blog/2019/05/09/tradestatistics/).
75 |
76 | 2. UN COMTRADE. (n.d.). United Nations Commodity Trade Statistics Database. Retrieved from [UN COMTRADE](https://comtrade.un.org/).
77 |
78 | ---
79 |
80 | This article format provides a clear, structured approach suitable for a scientific journal, emphasizing the methodology, open-source tools, and the impact of the OTS project on the accessibility of trade data.
81 | # References
82 |
--------------------------------------------------------------------------------
/svg/hexicon.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
341 |
--------------------------------------------------------------------------------
/tests/fixtures/vcr_cassettes/chl_all_2002_yrp.yml:
--------------------------------------------------------------------------------
1 | http_interactions:
2 | - request:
3 | method: get
4 | uri: https://api.tradestatistics.io/yrp?y=2002&r=chl&p=all
5 | body:
6 | encoding: ''
7 | string: ''
8 | headers:
9 | User-Agent: libcurl/7.81.0 r-curl/5.0.2 crul/1.4.0
10 | Accept-Encoding: gzip, deflate
11 | Accept: application/json, text/xml, application/xml, */*
12 | response:
13 | status:
14 | status_code: '200'
15 | message: OK
16 | explanation: Request fulfilled, document follows
17 | headers:
18 | status: HTTP/1.1 200 OK
19 | server: nginx/1.18.0 (Ubuntu)
20 | date: Thu, 22 Aug 2024 20:41:11 GMT
21 | content-type: application/json
22 | transfer-encoding: chunked
23 | connection: keep-alive
24 | content-encoding: gzip
25 | body:
26 | encoding: ''
27 | file: no
28 | string: '[{"year":2002,"reporter_iso":"chl","partner_iso":"are","trade_value_usd_imp":113,"trade_value_usd_exp":128287},{"year":2002,"reporter_iso":"chl","partner_iso":"arg","trade_value_usd_imp":919280993,"trade_value_usd_exp":191070218},{"year":2002,"reporter_iso":"chl","partner_iso":"aus","trade_value_usd_imp":8075304,"trade_value_usd_exp":11823093},{"year":2002,"reporter_iso":"chl","partner_iso":"aut","trade_value_usd_imp":1744474,"trade_value_usd_exp":711790},{"year":2002,"reporter_iso":"chl","partner_iso":"bel","trade_value_usd_imp":19823610,"trade_value_usd_exp":85385796},{"year":2002,"reporter_iso":"chl","partner_iso":"bhs","trade_value_usd_imp":538,"trade_value_usd_exp":200},{"year":2002,"reporter_iso":"chl","partner_iso":"bol","trade_value_usd_imp":8787683,"trade_value_usd_exp":51562019},{"year":2002,"reporter_iso":"chl","partner_iso":"bra","trade_value_usd_imp":554951374,"trade_value_usd_exp":275398579},{"year":2002,"reporter_iso":"chl","partner_iso":"can","trade_value_usd_imp":127925488,"trade_value_usd_exp":125091450},{"year":2002,"reporter_iso":"chl","partner_iso":"che","trade_value_usd_imp":16553609,"trade_value_usd_exp":11642719},{"year":2002,"reporter_iso":"chl","partner_iso":"chn","trade_value_usd_imp":88852315,"trade_value_usd_exp":11489015},{"year":2002,"reporter_iso":"chl","partner_iso":"col","trade_value_usd_imp":101337362,"trade_value_usd_exp":105126612},{"year":2002,"reporter_iso":"chl","partner_iso":"cri","trade_value_usd_imp":1888789,"trade_value_usd_exp":5685330},{"year":2002,"reporter_iso":"chl","partner_iso":"cub","trade_value_usd_imp":193566,"trade_value_usd_exp":445602},{"year":2002,"reporter_iso":"chl","partner_iso":"cze","trade_value_usd_imp":1170,"trade_value_usd_exp":400},{"year":2002,"reporter_iso":"chl","partner_iso":"deu","trade_value_usd_imp":226188566,"trade_value_usd_exp":171539627},{"year":2002,"reporter_iso":"chl","partner_iso":"dnk","trade_value_usd_imp":17121196,"trade_value_usd_exp":9045845},{"year":2002,"reporter_iso":"chl","partner_iso":"dom","trade_value_usd_imp":50264,"trade_value_usd_exp":3794195},{"year":2002,"reporter_iso":"chl","partner_iso":"ecu","trade_value_usd_imp":33221460,"trade_value_usd_exp":83089832},{"year":2002,"reporter_iso":"chl","partner_iso":"egy","trade_value_usd_imp":9341,"trade_value_usd_exp":19157},{"year":2002,"reporter_iso":"chl","partner_iso":"esp","trade_value_usd_imp":128120037,"trade_value_usd_exp":98540700},{"year":2002,"reporter_iso":"chl","partner_iso":"fin","trade_value_usd_imp":16826587,"trade_value_usd_exp":326523},{"year":2002,"reporter_iso":"chl","partner_iso":"fra","trade_value_usd_imp":207321172,"trade_value_usd_exp":477479039},{"year":2002,"reporter_iso":"chl","partner_iso":"gbr","trade_value_usd_imp":40271491,"trade_value_usd_exp":125105130},{"year":2002,"reporter_iso":"chl","partner_iso":"grc","trade_value_usd_imp":38205,"trade_value_usd_exp":186927},{"year":2002,"reporter_iso":"chl","partner_iso":"gtm","trade_value_usd_imp":382361,"trade_value_usd_exp":1553451},{"year":2002,"reporter_iso":"chl","partner_iso":"hnd","trade_value_usd_imp":53419,"trade_value_usd_exp":455093},{"year":2002,"reporter_iso":"chl","partner_iso":"hun","trade_value_usd_imp":122956,"trade_value_usd_exp":24748},{"year":2002,"reporter_iso":"chl","partner_iso":"idn","trade_value_usd_imp":408636,"trade_value_usd_exp":518338},{"year":2002,"reporter_iso":"chl","partner_iso":"ind","trade_value_usd_imp":3450456,"trade_value_usd_exp":8584867},{"year":2002,"reporter_iso":"chl","partner_iso":"irl","trade_value_usd_imp":3976755,"trade_value_usd_exp":27074899},{"year":2002,"reporter_iso":"chl","partner_iso":"isl","trade_value_usd_imp":749314,"trade_value_usd_exp":95046},{"year":2002,"reporter_iso":"chl","partner_iso":"isr","trade_value_usd_imp":6452417,"trade_value_usd_exp":2606926},{"year":2002,"reporter_iso":"chl","partner_iso":"ita","trade_value_usd_imp":68931833,"trade_value_usd_exp":59888870},{"year":2002,"reporter_iso":"chl","partner_iso":"jam","trade_value_usd_imp":11701,"trade_value_usd_exp":24151},{"year":2002,"reporter_iso":"chl","partner_iso":"jpn","trade_value_usd_imp":45762487,"trade_value_usd_exp":851310929},{"year":2002,"reporter_iso":"chl","partner_iso":"ken","trade_value_usd_imp":129,"trade_value_usd_exp":312903},{"year":2002,"reporter_iso":"chl","partner_iso":"kor","trade_value_usd_imp":94488861,"trade_value_usd_exp":36717638},{"year":2002,"reporter_iso":"chl","partner_iso":"mar","trade_value_usd_imp":93873,"trade_value_usd_exp":258484},{"year":2002,"reporter_iso":"chl","partner_iso":"mex","trade_value_usd_imp":193500770,"trade_value_usd_exp":284201405},{"year":2002,"reporter_iso":"chl","partner_iso":"mys","trade_value_usd_imp":392899,"trade_value_usd_exp":99005},{"year":2002,"reporter_iso":"chl","partner_iso":"nic","trade_value_usd_imp":710,"trade_value_usd_exp":1176},{"year":2002,"reporter_iso":"chl","partner_iso":"nld","trade_value_usd_imp":14480990,"trade_value_usd_exp":89495971},{"year":2002,"reporter_iso":"chl","partner_iso":"nor","trade_value_usd_imp":1598701,"trade_value_usd_exp":5001334},{"year":2002,"reporter_iso":"chl","partner_iso":"nzl","trade_value_usd_imp":1328402,"trade_value_usd_exp":1141916},{"year":2002,"reporter_iso":"chl","partner_iso":"pak","trade_value_usd_imp":186,"trade_value_usd_exp":12227},{"year":2002,"reporter_iso":"chl","partner_iso":"pan","trade_value_usd_imp":1486946,"trade_value_usd_exp":16127024},{"year":2002,"reporter_iso":"chl","partner_iso":"per","trade_value_usd_imp":84871581,"trade_value_usd_exp":276840220},{"year":2002,"reporter_iso":"chl","partner_iso":"phl","trade_value_usd_imp":1366154,"trade_value_usd_exp":601659},{"year":2002,"reporter_iso":"chl","partner_iso":"pol","trade_value_usd_imp":24373,"trade_value_usd_exp":7720},{"year":2002,"reporter_iso":"chl","partner_iso":"prt","trade_value_usd_imp":6726881,"trade_value_usd_exp":125178},{"year":2002,"reporter_iso":"chl","partner_iso":"pry","trade_value_usd_imp":1345633,"trade_value_usd_exp":9153213},{"year":2002,"reporter_iso":"chl","partner_iso":"rou","trade_value_usd_imp":28111,"trade_value_usd_exp":6618},{"year":2002,"reporter_iso":"chl","partner_iso":"rus","trade_value_usd_imp":80907,"trade_value_usd_exp":219832},{"year":2002,"reporter_iso":"chl","partner_iso":"sgp","trade_value_usd_imp":907722,"trade_value_usd_exp":17226690},{"year":2002,"reporter_iso":"chl","partner_iso":"slv","trade_value_usd_imp":20773,"trade_value_usd_exp":1702745},{"year":2002,"reporter_iso":"chl","partner_iso":"swe","trade_value_usd_imp":56114935,"trade_value_usd_exp":26474874},{"year":2002,"reporter_iso":"chl","partner_iso":"swz","trade_value_usd_imp":79130,"trade_value_usd_exp":19750},{"year":2002,"reporter_iso":"chl","partner_iso":"tha","trade_value_usd_imp":400466,"trade_value_usd_exp":1300829},{"year":2002,"reporter_iso":"chl","partner_iso":"tto","trade_value_usd_imp":54,"trade_value_usd_exp":708900},{"year":2002,"reporter_iso":"chl","partner_iso":"tur","trade_value_usd_imp":20402,"trade_value_usd_exp":870195},{"year":2002,"reporter_iso":"chl","partner_iso":"ury","trade_value_usd_imp":17734855,"trade_value_usd_exp":14611191},{"year":2002,"reporter_iso":"chl","partner_iso":"usa","trade_value_usd_imp":1718277875,"trade_value_usd_exp":2592659966},{"year":2002,"reporter_iso":"chl","partner_iso":"ven","trade_value_usd_imp":6775652,"trade_value_usd_exp":32892482},{"year":2002,"reporter_iso":"chl","partner_iso":"vnm","trade_value_usd_imp":2349,"trade_value_usd_exp":102024},{"year":2002,"reporter_iso":"chl","partner_iso":"zaf","trade_value_usd_imp":1954501,"trade_value_usd_exp":3685274}]'
29 | recorded_at: 2024-08-22 20:41:12 GMT
30 | recorded_with: vcr/1.2.2, webmockr/0.9.0
31 | - request:
32 | method: get
33 | uri: https://api.tradestatistics.io/yrp?y=2002&r=all&p=chl
34 | body:
35 | encoding: ''
36 | string: ''
37 | headers:
38 | User-Agent: libcurl/7.81.0 r-curl/5.0.2 crul/1.4.0
39 | Accept-Encoding: gzip, deflate
40 | Accept: application/json, text/xml, application/xml, */*
41 | response:
42 | status:
43 | status_code: '200'
44 | message: OK
45 | explanation: Request fulfilled, document follows
46 | headers:
47 | status: HTTP/1.1 200 OK
48 | server: nginx/1.18.0 (Ubuntu)
49 | date: Thu, 22 Aug 2024 20:41:11 GMT
50 | content-type: application/json
51 | transfer-encoding: chunked
52 | connection: keep-alive
53 | content-encoding: gzip
54 | body:
55 | encoding: ''
56 | file: no
57 | string: '[{"year":2002,"reporter_iso":"arg","partner_iso":"chl","trade_value_usd_imp":142974825,"trade_value_usd_exp":659040090},{"year":2002,"reporter_iso":"aus","partner_iso":"chl","trade_value_usd_imp":5927021,"trade_value_usd_exp":18821676},{"year":2002,"reporter_iso":"aut","partner_iso":"chl","trade_value_usd_imp":3703754,"trade_value_usd_exp":6432924},{"year":2002,"reporter_iso":"bel","partner_iso":"chl","trade_value_usd_imp":63504489,"trade_value_usd_exp":18560840},{"year":2002,"reporter_iso":"ben","partner_iso":"chl","trade_value_usd_imp":157126,"trade_value_usd_exp":14891},{"year":2002,"reporter_iso":"bgr","partner_iso":"chl","trade_value_usd_imp":8119,"trade_value_usd_exp":2541},{"year":2002,"reporter_iso":"bhs","partner_iso":"chl","trade_value_usd_imp":7369,"trade_value_usd_exp":42000},{"year":2002,"reporter_iso":"bol","partner_iso":"chl","trade_value_usd_imp":52609760,"trade_value_usd_exp":9962049},{"year":2002,"reporter_iso":"bra","partner_iso":"chl","trade_value_usd_imp":184085618,"trade_value_usd_exp":331962225},{"year":2002,"reporter_iso":"brb","partner_iso":"chl","trade_value_usd_imp":598468,"trade_value_usd_exp":3145},{"year":2002,"reporter_iso":"can","partner_iso":"chl","trade_value_usd_imp":66081424,"trade_value_usd_exp":48418322},{"year":2002,"reporter_iso":"che","partner_iso":"chl","trade_value_usd_imp":13938782,"trade_value_usd_exp":36120805},{"year":2002,"reporter_iso":"chn","partner_iso":"chl","trade_value_usd_imp":8385305,"trade_value_usd_exp":111112104},{"year":2002,"reporter_iso":"col","partner_iso":"chl","trade_value_usd_imp":67098993,"trade_value_usd_exp":76202284},{"year":2002,"reporter_iso":"cri","partner_iso":"chl","trade_value_usd_imp":4119549,"trade_value_usd_exp":2368224},{"year":2002,"reporter_iso":"cub","partner_iso":"chl","trade_value_usd_imp":8084466,"trade_value_usd_exp":384049},{"year":2002,"reporter_iso":"cyp","partner_iso":"chl","trade_value_usd_imp":373,"trade_value_usd_exp":16},{"year":2002,"reporter_iso":"cze","partner_iso":"chl","trade_value_usd_imp":4304,"trade_value_usd_exp":22408},{"year":2002,"reporter_iso":"deu","partner_iso":"chl","trade_value_usd_imp":101671000,"trade_value_usd_exp":212573000},{"year":2002,"reporter_iso":"dnk","partner_iso":"chl","trade_value_usd_imp":36539411,"trade_value_usd_exp":26076587},{"year":2002,"reporter_iso":"dom","partner_iso":"chl","trade_value_usd_imp":1845371,"trade_value_usd_exp":160796},{"year":2002,"reporter_iso":"ecu","partner_iso":"chl","trade_value_usd_imp":75511113,"trade_value_usd_exp":18489779},{"year":2002,"reporter_iso":"esp","partner_iso":"chl","trade_value_usd_imp":105370339,"trade_value_usd_exp":173697249},{"year":2002,"reporter_iso":"fin","partner_iso":"chl","trade_value_usd_imp":294783,"trade_value_usd_exp":17834846},{"year":2002,"reporter_iso":"fji","partner_iso":"chl","trade_value_usd_imp":485883,"trade_value_usd_exp":4390},{"year":2002,"reporter_iso":"fra","partner_iso":"chl","trade_value_usd_imp":82163006,"trade_value_usd_exp":237590301},{"year":2002,"reporter_iso":"gbr","partner_iso":"chl","trade_value_usd_imp":298916536,"trade_value_usd_exp":52447460},{"year":2002,"reporter_iso":"grc","partner_iso":"chl","trade_value_usd_imp":108909,"trade_value_usd_exp":8246196},{"year":2002,"reporter_iso":"gtm","partner_iso":"chl","trade_value_usd_imp":2501623,"trade_value_usd_exp":96372},{"year":2002,"reporter_iso":"hkg","partner_iso":"chl","trade_value_usd_imp":3045903,"trade_value_usd_exp":114278494},{"year":2002,"reporter_iso":"hnd","partner_iso":"chl","trade_value_usd_imp":5997857,"trade_value_usd_exp":166483},{"year":2002,"reporter_iso":"hrv","partner_iso":"chl","trade_value_usd_imp":364,"trade_value_usd_exp":8634},{"year":2002,"reporter_iso":"hun","partner_iso":"chl","trade_value_usd_imp":1741000,"trade_value_usd_exp":56000},{"year":2002,"reporter_iso":"idn","partner_iso":"chl","trade_value_usd_imp":597976,"trade_value_usd_exp":282060},{"year":2002,"reporter_iso":"ind","partner_iso":"chl","trade_value_usd_imp":440135,"trade_value_usd_exp":2472298},{"year":2002,"reporter_iso":"irl","partner_iso":"chl","trade_value_usd_imp":107718,"trade_value_usd_exp":1543540},{"year":2002,"reporter_iso":"isl","partner_iso":"chl","trade_value_usd_imp":43333,"trade_value_usd_exp":244580},{"year":2002,"reporter_iso":"isr","partner_iso":"chl","trade_value_usd_imp":2776000,"trade_value_usd_exp":8843000},{"year":2002,"reporter_iso":"ita","partner_iso":"chl","trade_value_usd_imp":60830567,"trade_value_usd_exp":86659531},{"year":2002,"reporter_iso":"jam","partner_iso":"chl","trade_value_usd_imp":43395,"trade_value_usd_exp":27936},{"year":2002,"reporter_iso":"jpn","partner_iso":"chl","trade_value_usd_imp":19375082,"trade_value_usd_exp":24728704},{"year":2002,"reporter_iso":"kor","partner_iso":"chl","trade_value_usd_imp":1645126,"trade_value_usd_exp":111781352},{"year":2002,"reporter_iso":"lca","partner_iso":"chl","trade_value_usd_imp":245067,"trade_value_usd_exp":8984},{"year":2002,"reporter_iso":"ltu","partner_iso":"chl","trade_value_usd_imp":95,"trade_value_usd_exp":650},{"year":2002,"reporter_iso":"lux","partner_iso":"chl","trade_value_usd_imp":1368,"trade_value_usd_exp":2095},{"year":2002,"reporter_iso":"lva","partner_iso":"chl","trade_value_usd_imp":1766600,"trade_value_usd_exp":435985},{"year":2002,"reporter_iso":"mac","partner_iso":"chl","trade_value_usd_imp":50555,"trade_value_usd_exp":13376},{"year":2002,"reporter_iso":"mar","partner_iso":"chl","trade_value_usd_imp":253746,"trade_value_usd_exp":170408},{"year":2002,"reporter_iso":"mex","partner_iso":"chl","trade_value_usd_imp":230932665,"trade_value_usd_exp":121266249},{"year":2002,"reporter_iso":"mus","partner_iso":"chl","trade_value_usd_imp":34498,"trade_value_usd_exp":246},{"year":2002,"reporter_iso":"mys","partner_iso":"chl","trade_value_usd_imp":844470,"trade_value_usd_exp":1455357},{"year":2002,"reporter_iso":"nic","partner_iso":"chl","trade_value_usd_imp":41203,"trade_value_usd_exp":3862},{"year":2002,"reporter_iso":"nld","partner_iso":"chl","trade_value_usd_imp":101486921,"trade_value_usd_exp":20389587},{"year":2002,"reporter_iso":"nor","partner_iso":"chl","trade_value_usd_imp":19140302,"trade_value_usd_exp":5838232},{"year":2002,"reporter_iso":"nzl","partner_iso":"chl","trade_value_usd_imp":812017,"trade_value_usd_exp":1240113},{"year":2002,"reporter_iso":"pan","partner_iso":"chl","trade_value_usd_imp":2551,"trade_value_usd_exp":26306},{"year":2002,"reporter_iso":"per","partner_iso":"chl","trade_value_usd_imp":191938214,"trade_value_usd_exp":86242952},{"year":2002,"reporter_iso":"phl","partner_iso":"chl","trade_value_usd_imp":649839,"trade_value_usd_exp":1684759},{"year":2002,"reporter_iso":"prt","partner_iso":"chl","trade_value_usd_imp":648086,"trade_value_usd_exp":28626613},{"year":2002,"reporter_iso":"pry","partner_iso":"chl","trade_value_usd_imp":3022471,"trade_value_usd_exp":2354950},{"year":2002,"reporter_iso":"pyf","partner_iso":"chl","trade_value_usd_imp":1108,"trade_value_usd_exp":5302},{"year":2002,"reporter_iso":"rou","partner_iso":"chl","trade_value_usd_imp":487,"trade_value_usd_exp":2240},{"year":2002,"reporter_iso":"rus","partner_iso":"chl","trade_value_usd_imp":3944941,"trade_value_usd_exp":4246},{"year":2002,"reporter_iso":"scg","partner_iso":"chl","trade_value_usd_imp":245,"trade_value_usd_exp":1105},{"year":2002,"reporter_iso":"sgp","partner_iso":"chl","trade_value_usd_imp":8244510,"trade_value_usd_exp":1224312},{"year":2002,"reporter_iso":"slv","partner_iso":"chl","trade_value_usd_imp":3657288,"trade_value_usd_exp":204272},{"year":2002,"reporter_iso":"sur","partner_iso":"chl","trade_value_usd_imp":59410,"trade_value_usd_exp":2304},{"year":2002,"reporter_iso":"svk","partner_iso":"chl","trade_value_usd_imp":17010,"trade_value_usd_exp":12181},{"year":2002,"reporter_iso":"svn","partner_iso":"chl","trade_value_usd_imp":1669,"trade_value_usd_exp":34343},{"year":2002,"reporter_iso":"swe","partner_iso":"chl","trade_value_usd_imp":2176514,"trade_value_usd_exp":55755505},{"year":2002,"reporter_iso":"tgo","partner_iso":"chl","trade_value_usd_imp":140998,"trade_value_usd_exp":4438},{"year":2002,"reporter_iso":"tha","partner_iso":"chl","trade_value_usd_imp":548111,"trade_value_usd_exp":4782248},{"year":2002,"reporter_iso":"tto","partner_iso":"chl","trade_value_usd_imp":151,"trade_value_usd_exp":24},{"year":2002,"reporter_iso":"tur","partner_iso":"chl","trade_value_usd_imp":1171334,"trade_value_usd_exp":39448},{"year":2002,"reporter_iso":"ury","partner_iso":"chl","trade_value_usd_imp":9232448,"trade_value_usd_exp":10776011},{"year":2002,"reporter_iso":"usa","partner_iso":"chl","trade_value_usd_imp":2582218461,"trade_value_usd_exp":1403122172},{"year":2002,"reporter_iso":"ven","partner_iso":"chl","trade_value_usd_imp":14490612,"trade_value_usd_exp":13367557},{"year":2002,"reporter_iso":"vnm","partner_iso":"chl","trade_value_usd_imp":154838,"trade_value_usd_exp":192482},{"year":2002,"reporter_iso":"zaf","partner_iso":"chl","trade_value_usd_imp":1453418,"trade_value_usd_exp":3168763}]'
58 | recorded_at: 2024-08-22 20:41:12 GMT
59 | recorded_with: vcr/1.2.2, webmockr/0.9.0
60 |
--------------------------------------------------------------------------------
/tests/fixtures/vcr_cassettes/chl_arg_2002_yr.yml:
--------------------------------------------------------------------------------
1 | http_interactions:
2 | - request:
3 | method: get
4 | uri: https://api.tradestatistics.io/yr?y=2002&r=chl
5 | body:
6 | encoding: ''
7 | string: ''
8 | headers:
9 | User-Agent: libcurl/7.81.0 r-curl/5.0.2 crul/1.4.0
10 | Accept-Encoding: gzip, deflate
11 | Accept: application/json, text/xml, application/xml, */*
12 | response:
13 | status:
14 | status_code: '200'
15 | message: OK
16 | explanation: Request fulfilled, document follows
17 | headers:
18 | status: HTTP/1.1 200 OK
19 | server: nginx/1.18.0 (Ubuntu)
20 | date: Thu, 22 Aug 2024 20:41:12 GMT
21 | content-type: application/json
22 | transfer-encoding: chunked
23 | connection: keep-alive
24 | content-encoding: gzip
25 | body:
26 | encoding: ''
27 | file: no
28 | string: '[{"year":2002,"reporter_iso":"chl","trade_value_usd_imp":4852991863,"trade_value_usd_exp":6209403846}]'
29 | recorded_at: 2024-08-22 20:41:13 GMT
30 | recorded_with: vcr/1.2.2, webmockr/0.9.0
31 | - request:
32 | method: get
33 | uri: https://api.tradestatistics.io/yr?y=2002&r=arg
34 | body:
35 | encoding: ''
36 | string: ''
37 | headers:
38 | User-Agent: libcurl/7.81.0 r-curl/5.0.2 crul/1.4.0
39 | Accept-Encoding: gzip, deflate
40 | Accept: application/json, text/xml, application/xml, */*
41 | response:
42 | status:
43 | status_code: '200'
44 | message: OK
45 | explanation: Request fulfilled, document follows
46 | headers:
47 | status: HTTP/1.1 200 OK
48 | server: nginx/1.18.0 (Ubuntu)
49 | date: Thu, 22 Aug 2024 20:41:12 GMT
50 | content-type: application/json
51 | transfer-encoding: chunked
52 | connection: keep-alive
53 | content-encoding: gzip
54 | body:
55 | encoding: ''
56 | file: no
57 | string: '[{"year":2002,"reporter_iso":"arg","trade_value_usd_imp":4961344697,"trade_value_usd_exp":8520263167}]'
58 | recorded_at: 2024-08-22 20:41:13 GMT
59 | recorded_with: vcr/1.2.2, webmockr/0.9.0
60 | - request:
61 | method: get
62 | uri: https://api.tradestatistics.io/yrp?y=2002&r=mex&p=usa
63 | body:
64 | encoding: ''
65 | string: ''
66 | headers:
67 | User-Agent: libcurl/7.81.0 r-curl/5.0.2 crul/1.4.0
68 | Accept-Encoding: gzip, deflate
69 | Accept: application/json, text/xml, application/xml, */*
70 | response:
71 | status:
72 | status_code: '200'
73 | message: OK
74 | explanation: Request fulfilled, document follows
75 | headers:
76 | status: HTTP/1.1 200 OK
77 | server: nginx/1.18.0 (Ubuntu)
78 | date: Thu, 22 Aug 2024 20:41:13 GMT
79 | content-type: application/json
80 | transfer-encoding: chunked
81 | connection: keep-alive
82 | content-encoding: gzip
83 | body:
84 | encoding: ''
85 | file: no
86 | string: '[{"year":2002,"reporter_iso":"mex","partner_iso":"usa","trade_value_usd_imp":103352303539,"trade_value_usd_exp":137489947084}]'
87 | recorded_at: 2024-08-22 20:41:13 GMT
88 | recorded_with: vcr/1.2.2, webmockr/0.9.0
89 | - request:
90 | method: get
91 | uri: https://api.tradestatistics.io/yrp?y=2002&r=mex&p=can
92 | body:
93 | encoding: ''
94 | string: ''
95 | headers:
96 | User-Agent: libcurl/7.81.0 r-curl/5.0.2 crul/1.4.0
97 | Accept-Encoding: gzip, deflate
98 | Accept: application/json, text/xml, application/xml, */*
99 | response:
100 | status:
101 | status_code: '200'
102 | message: OK
103 | explanation: Request fulfilled, document follows
104 | headers:
105 | status: HTTP/1.1 200 OK
106 | server: nginx/1.18.0 (Ubuntu)
107 | date: Thu, 22 Aug 2024 20:41:13 GMT
108 | content-type: application/json
109 | transfer-encoding: chunked
110 | connection: keep-alive
111 | content-encoding: gzip
112 | body:
113 | encoding: ''
114 | file: no
115 | string: '[{"year":2002,"reporter_iso":"mex","partner_iso":"can","trade_value_usd_imp":3127702740,"trade_value_usd_exp":2580061542}]'
116 | recorded_at: 2024-08-22 20:41:13 GMT
117 | recorded_with: vcr/1.2.2, webmockr/0.9.0
118 |
--------------------------------------------------------------------------------
/tests/fixtures/vcr_cassettes/chl_arg_2002_yr_apple.yml:
--------------------------------------------------------------------------------
1 | http_interactions:
2 | - request:
3 | method: get
4 | uri: https://api.tradestatistics.io/yr?y=2002&r=all
5 | body:
6 | encoding: ''
7 | string: ''
8 | headers:
9 | User-Agent: libcurl/7.81.0 r-curl/5.0.2 crul/1.4.0
10 | Accept-Encoding: gzip, deflate
11 | Accept: application/json, text/xml, application/xml, */*
12 | response:
13 | status:
14 | status_code: '200'
15 | message: OK
16 | explanation: Request fulfilled, document follows
17 | headers:
18 | status: HTTP/1.1 200 OK
19 | server: nginx/1.18.0 (Ubuntu)
20 | date: Thu, 22 Aug 2024 20:41:11 GMT
21 | content-type: application/json
22 | transfer-encoding: chunked
23 | connection: keep-alive
24 | content-encoding: gzip
25 | body:
26 | encoding: ''
27 | file: no
28 | string: '[{"year":2002,"reporter_iso":"abw","trade_value_usd_imp":10942581,"trade_value_usd_exp":187806},{"year":2002,"reporter_iso":"aia","trade_value_usd_imp":35707926,"trade_value_usd_exp":3903265},{"year":2002,"reporter_iso":"alb","trade_value_usd_imp":412367680,"trade_value_usd_exp":285851188},{"year":2002,"reporter_iso":"and","trade_value_usd_imp":636582295,"trade_value_usd_exp":58444485},{"year":2002,"reporter_iso":"are","trade_value_usd_imp":237528280,"trade_value_usd_exp":10232773},{"year":2002,"reporter_iso":"arg","trade_value_usd_imp":4961344697,"trade_value_usd_exp":8520263167},{"year":2002,"reporter_iso":"arm","trade_value_usd_imp":278238973,"trade_value_usd_exp":273231146},{"year":2002,"reporter_iso":"aus","trade_value_usd_imp":50614436619,"trade_value_usd_exp":22929823191},{"year":2002,"reporter_iso":"aut","trade_value_usd_imp":59914205291,"trade_value_usd_exp":62342104114},{"year":2002,"reporter_iso":"aze","trade_value_usd_imp":251359340,"trade_value_usd_exp":322330955},{"year":2002,"reporter_iso":"bdi","trade_value_usd_imp":2003981,"trade_value_usd_exp":373113},{"year":2002,"reporter_iso":"bel","trade_value_usd_imp":177003889903,"trade_value_usd_exp":196713094250},{"year":2002,"reporter_iso":"ben","trade_value_usd_imp":158227415,"trade_value_usd_exp":19142926},{"year":2002,"reporter_iso":"bfa","trade_value_usd_imp":83895024,"trade_value_usd_exp":86119080},{"year":2002,"reporter_iso":"bgd","trade_value_usd_imp":1519701286,"trade_value_usd_exp":2826005790},{"year":2002,"reporter_iso":"bgr","trade_value_usd_imp":4689562320,"trade_value_usd_exp":3573042187},{"year":2002,"reporter_iso":"bhr","trade_value_usd_imp":595217741,"trade_value_usd_exp":930460794},{"year":2002,"reporter_iso":"bhs","trade_value_usd_imp":1153108535,"trade_value_usd_exp":332001358},{"year":2002,"reporter_iso":"blr","trade_value_usd_imp":5848955500,"trade_value_usd_exp":6209004700},{"year":2002,"reporter_iso":"blz","trade_value_usd_imp":13485289,"trade_value_usd_exp":108977321},{"year":2002,"reporter_iso":"bol","trade_value_usd_imp":369447324,"trade_value_usd_exp":219030029},{"year":2002,"reporter_iso":"bra","trade_value_usd_imp":28844395511,"trade_value_usd_exp":23421217684},{"year":2002,"reporter_iso":"brb","trade_value_usd_imp":421323565,"trade_value_usd_exp":110487216},{"year":2002,"reporter_iso":"brn","trade_value_usd_imp":499518290,"trade_value_usd_exp":403086486},{"year":2002,"reporter_iso":"bwa","trade_value_usd_imp":2680543175,"trade_value_usd_exp":2537082180},{"year":2002,"reporter_iso":"caf","trade_value_usd_imp":7146377,"trade_value_usd_exp":921530},{"year":2002,"reporter_iso":"can","trade_value_usd_imp":184411112206,"trade_value_usd_exp":235913387639},{"year":2002,"reporter_iso":"che","trade_value_usd_imp":91024722911,"trade_value_usd_exp":91379612361},{"year":2002,"reporter_iso":"chl","trade_value_usd_imp":4852991863,"trade_value_usd_exp":6209403846},{"year":2002,"reporter_iso":"chn","trade_value_usd_imp":175308989511,"trade_value_usd_exp":260658759053},{"year":2002,"reporter_iso":"civ","trade_value_usd_imp":400894658,"trade_value_usd_exp":560360380},{"year":2002,"reporter_iso":"cmr","trade_value_usd_imp":168741675,"trade_value_usd_exp":640281619},{"year":2002,"reporter_iso":"col","trade_value_usd_imp":4055399338,"trade_value_usd_exp":6788995024},{"year":2002,"reporter_iso":"com","trade_value_usd_imp":2865191,"trade_value_usd_exp":143306},{"year":2002,"reporter_iso":"cpv","trade_value_usd_imp":1310305,"trade_value_usd_exp":3923961},{"year":2002,"reporter_iso":"cri","trade_value_usd_imp":3783069384,"trade_value_usd_exp":3880676233},{"year":2002,"reporter_iso":"cub","trade_value_usd_imp":422315437,"trade_value_usd_exp":128329512},{"year":2002,"reporter_iso":"cyp","trade_value_usd_imp":1324535631,"trade_value_usd_exp":433765579},{"year":2002,"reporter_iso":"cze","trade_value_usd_imp":37055851919,"trade_value_usd_exp":39715280571},{"year":2002,"reporter_iso":"deu","trade_value_usd_imp":419383375000,"trade_value_usd_exp":539398418000},{"year":2002,"reporter_iso":"dma","trade_value_usd_imp":12723871,"trade_value_usd_exp":18365844},{"year":2002,"reporter_iso":"dnk","trade_value_usd_imp":41197909821,"trade_value_usd_exp":42570906792},{"year":2002,"reporter_iso":"dom","trade_value_usd_imp":2205780046,"trade_value_usd_exp":4770710866},{"year":2002,"reporter_iso":"dza","trade_value_usd_imp":1846278671,"trade_value_usd_exp":3716405875},{"year":2002,"reporter_iso":"ecu","trade_value_usd_imp":1683774594,"trade_value_usd_exp":2080593109},{"year":2002,"reporter_iso":"egy","trade_value_usd_imp":1428623274,"trade_value_usd_exp":1003953594},{"year":2002,"reporter_iso":"esp","trade_value_usd_imp":129713707652,"trade_value_usd_exp":106267952342},{"year":2002,"reporter_iso":"est","trade_value_usd_imp":2362889973,"trade_value_usd_exp":2879318254},{"year":2002,"reporter_iso":"eth","trade_value_usd_imp":17059119,"trade_value_usd_exp":3945360},{"year":2002,"reporter_iso":"fin","trade_value_usd_imp":22213270715,"trade_value_usd_exp":28943621792},{"year":2002,"reporter_iso":"fji","trade_value_usd_imp":342831820,"trade_value_usd_exp":243678274},{"year":2002,"reporter_iso":"fra","trade_value_usd_imp":257645949046,"trade_value_usd_exp":256515127553},{"year":2002,"reporter_iso":"fro","trade_value_usd_imp":37486716,"trade_value_usd_exp":171434936},{"year":2002,"reporter_iso":"gab","trade_value_usd_imp":173914835,"trade_value_usd_exp":26611981},{"year":2002,"reporter_iso":"gbr","trade_value_usd_imp":325601674729,"trade_value_usd_exp":250344164086},{"year":2002,"reporter_iso":"geo","trade_value_usd_imp":167991447,"trade_value_usd_exp":110479992},{"year":2002,"reporter_iso":"gin","trade_value_usd_imp":35943911,"trade_value_usd_exp":19888036},{"year":2002,"reporter_iso":"gmb","trade_value_usd_imp":6735046,"trade_value_usd_exp":877595},{"year":2002,"reporter_iso":"grc","trade_value_usd_imp":14540914831,"trade_value_usd_exp":6158973391},{"year":2002,"reporter_iso":"grd","trade_value_usd_imp":41394615,"trade_value_usd_exp":11567646},{"year":2002,"reporter_iso":"grl","trade_value_usd_imp":100008108,"trade_value_usd_exp":244851107},{"year":2002,"reporter_iso":"gtm","trade_value_usd_imp":3337786716,"trade_value_usd_exp":1485518070},{"year":2002,"reporter_iso":"guy","trade_value_usd_imp":186696654,"trade_value_usd_exp":128435805},{"year":2002,"reporter_iso":"hkg","trade_value_usd_imp":177498598015,"trade_value_usd_exp":188472964790},{"year":2002,"reporter_iso":"hnd","trade_value_usd_imp":1289120260,"trade_value_usd_exp":589829672},{"year":2002,"reporter_iso":"hrv","trade_value_usd_imp":5481293617,"trade_value_usd_exp":3619955373},{"year":2002,"reporter_iso":"hun","trade_value_usd_imp":27286215000,"trade_value_usd_exp":29599187000},{"year":2002,"reporter_iso":"idn","trade_value_usd_imp":15016286827,"trade_value_usd_exp":31693903578},{"year":2002,"reporter_iso":"ind","trade_value_usd_imp":22808999446,"trade_value_usd_exp":26505226658},{"year":2002,"reporter_iso":"irl","trade_value_usd_imp":40147153919,"trade_value_usd_exp":80141196424},{"year":2002,"reporter_iso":"irn","trade_value_usd_imp":3912321225,"trade_value_usd_exp":941971174},{"year":2002,"reporter_iso":"isl","trade_value_usd_imp":567208579,"trade_value_usd_exp":555476831},{"year":2002,"reporter_iso":"isr","trade_value_usd_imp":14758593000,"trade_value_usd_exp":24102390000},{"year":2002,"reporter_iso":"ita","trade_value_usd_imp":196208719286,"trade_value_usd_exp":214893079682},{"year":2002,"reporter_iso":"jam","trade_value_usd_imp":1217757586,"trade_value_usd_exp":350725896},{"year":2002,"reporter_iso":"jor","trade_value_usd_imp":1156006657,"trade_value_usd_exp":569017023},{"year":2002,"reporter_iso":"jpn","trade_value_usd_imp":204725204793,"trade_value_usd_exp":323675145981},{"year":2002,"reporter_iso":"kaz","trade_value_usd_imp":2791977000,"trade_value_usd_exp":2183009100},{"year":2002,"reporter_iso":"ken","trade_value_usd_imp":644357715,"trade_value_usd_exp":557753904},{"year":2002,"reporter_iso":"kgz","trade_value_usd_imp":177164538,"trade_value_usd_exp":115754770},{"year":2002,"reporter_iso":"khm","trade_value_usd_imp":711441107,"trade_value_usd_exp":306980733},{"year":2002,"reporter_iso":"kna","trade_value_usd_imp":71625392,"trade_value_usd_exp":34483618},{"year":2002,"reporter_iso":"kor","trade_value_usd_imp":93974135291,"trade_value_usd_exp":123533860815},{"year":2002,"reporter_iso":"kwt","trade_value_usd_imp":6110506988,"trade_value_usd_exp":728704666},{"year":2002,"reporter_iso":"lbn","trade_value_usd_imp":1855724916,"trade_value_usd_exp":517261157},{"year":2002,"reporter_iso":"lca","trade_value_usd_imp":119570730,"trade_value_usd_exp":26643205},{"year":2002,"reporter_iso":"lka","trade_value_usd_imp":2071942622,"trade_value_usd_exp":3026703519},{"year":2002,"reporter_iso":"lso","trade_value_usd_imp":440191508,"trade_value_usd_exp":194522067},{"year":2002,"reporter_iso":"ltu","trade_value_usd_imp":3501499774,"trade_value_usd_exp":4059190284},{"year":2002,"reporter_iso":"lux","trade_value_usd_imp":9201085526,"trade_value_usd_exp":6941870982},{"year":2002,"reporter_iso":"lva","trade_value_usd_imp":1708938227,"trade_value_usd_exp":1438805502},{"year":2002,"reporter_iso":"mac","trade_value_usd_imp":1409144048,"trade_value_usd_exp":1346469035},{"year":2002,"reporter_iso":"mar","trade_value_usd_imp":3867481257,"trade_value_usd_exp":5124435935},{"year":2002,"reporter_iso":"mda","trade_value_usd_imp":220549524,"trade_value_usd_exp":290335515},{"year":2002,"reporter_iso":"mdg","trade_value_usd_imp":145913121,"trade_value_usd_exp":252934372},{"year":2002,"reporter_iso":"mdv","trade_value_usd_imp":101964,"trade_value_usd_exp":19533326},{"year":2002,"reporter_iso":"mex","trade_value_usd_imp":138050056482,"trade_value_usd_exp":147703351420},{"year":2002,"reporter_iso":"mkd","trade_value_usd_imp":781933258,"trade_value_usd_exp":698384166},{"year":2002,"reporter_iso":"mli","trade_value_usd_imp":308272551,"trade_value_usd_exp":23110540},{"year":2002,"reporter_iso":"mlt","trade_value_usd_imp":1643666560,"trade_value_usd_exp":1591309520},{"year":2002,"reporter_iso":"moz","trade_value_usd_imp":413481498,"trade_value_usd_exp":149570556},{"year":2002,"reporter_iso":"mrt","trade_value_usd_imp":298108,"trade_value_usd_exp":24463245},{"year":2002,"reporter_iso":"msr","trade_value_usd_imp":6545137,"trade_value_usd_exp":446140},{"year":2002,"reporter_iso":"mus","trade_value_usd_imp":673607695,"trade_value_usd_exp":834307798},{"year":2002,"reporter_iso":"mwi","trade_value_usd_imp":158258300,"trade_value_usd_exp":92140023},{"year":2002,"reporter_iso":"mys","trade_value_usd_imp":59716921371,"trade_value_usd_exp":74007863464},{"year":2002,"reporter_iso":"myt","trade_value_usd_imp":31693648,"trade_value_usd_exp":4554694},{"year":2002,"reporter_iso":"nam","trade_value_usd_imp":977687092,"trade_value_usd_exp":883241029},{"year":2002,"reporter_iso":"ncl","trade_value_usd_imp":228397802,"trade_value_usd_exp":40227026},{"year":2002,"reporter_iso":"ner","trade_value_usd_imp":121296195,"trade_value_usd_exp":148102574},{"year":2002,"reporter_iso":"nga","trade_value_usd_imp":243238361,"trade_value_usd_exp":9467001280},{"year":2002,"reporter_iso":"nic","trade_value_usd_imp":494021702,"trade_value_usd_exp":189038528},{"year":2002,"reporter_iso":"nld","trade_value_usd_imp":126477039562,"trade_value_usd_exp":147577731294},{"year":2002,"reporter_iso":"nor","trade_value_usd_imp":23527830667,"trade_value_usd_exp":29337248780},{"year":2002,"reporter_iso":"nzl","trade_value_usd_imp":8603571540,"trade_value_usd_exp":5461318405},{"year":2002,"reporter_iso":"omn","trade_value_usd_imp":3040788127,"trade_value_usd_exp":1582423954},{"year":2002,"reporter_iso":"pan","trade_value_usd_imp":269995397,"trade_value_usd_exp":224085869},{"year":2002,"reporter_iso":"per","trade_value_usd_imp":2239908755,"trade_value_usd_exp":2386060346},{"year":2002,"reporter_iso":"phl","trade_value_usd_imp":27332296584,"trade_value_usd_exp":28944435456},{"year":2002,"reporter_iso":"png","trade_value_usd_imp":517609227,"trade_value_usd_exp":133270960},{"year":2002,"reporter_iso":"pol","trade_value_usd_imp":28829886000,"trade_value_usd_exp":27339782000},{"year":2002,"reporter_iso":"prt","trade_value_usd_imp":26317954787,"trade_value_usd_exp":22298987680},{"year":2002,"reporter_iso":"pry","trade_value_usd_imp":416513541,"trade_value_usd_exp":1482990923},{"year":2002,"reporter_iso":"pyf","trade_value_usd_imp":212058213,"trade_value_usd_exp":23569261},{"year":2002,"reporter_iso":"qat","trade_value_usd_imp":1503884558,"trade_value_usd_exp":1127916793},{"year":2002,"reporter_iso":"rou","trade_value_usd_imp":9890586452,"trade_value_usd_exp":10507577421},{"year":2002,"reporter_iso":"rus","trade_value_usd_imp":22169756678,"trade_value_usd_exp":31568278266},{"year":2002,"reporter_iso":"rwa","trade_value_usd_imp":15918405,"trade_value_usd_exp":5073358},{"year":2002,"reporter_iso":"sau","trade_value_usd_imp":6714716114,"trade_value_usd_exp":1956998137},{"year":2002,"reporter_iso":"scg","trade_value_usd_imp":1814285993,"trade_value_usd_exp":1291350613},{"year":2002,"reporter_iso":"sdn","trade_value_usd_imp":154509610,"trade_value_usd_exp":777678417},{"year":2002,"reporter_iso":"sen","trade_value_usd_imp":462449915,"trade_value_usd_exp":39963531},{"year":2002,"reporter_iso":"sgp","trade_value_usd_imp":94243528681,"trade_value_usd_exp":109100173140},{"year":2002,"reporter_iso":"sle","trade_value_usd_imp":16456126,"trade_value_usd_exp":314356},{"year":2002,"reporter_iso":"slv","trade_value_usd_imp":4102235758,"trade_value_usd_exp":4441771827},{"year":2002,"reporter_iso":"stp","trade_value_usd_imp":450635,"trade_value_usd_exp":95743},{"year":2002,"reporter_iso":"sur","trade_value_usd_imp":261612449,"trade_value_usd_exp":93127618},{"year":2002,"reporter_iso":"svk","trade_value_usd_imp":10781024143,"trade_value_usd_exp":12211970806},{"year":2002,"reporter_iso":"svn","trade_value_usd_imp":7551394735,"trade_value_usd_exp":8516641408},{"year":2002,"reporter_iso":"swe","trade_value_usd_imp":57228831774,"trade_value_usd_exp":68423900441},{"year":2002,"reporter_iso":"swz","trade_value_usd_imp":665485278,"trade_value_usd_exp":192560635},{"year":2002,"reporter_iso":"syc","trade_value_usd_imp":83739027,"trade_value_usd_exp":69475902},{"year":2002,"reporter_iso":"syr","trade_value_usd_imp":1778910509,"trade_value_usd_exp":1867206414},{"year":2002,"reporter_iso":"tca","trade_value_usd_imp":1641204,"trade_value_usd_exp":14368},{"year":2002,"reporter_iso":"tgo","trade_value_usd_imp":97015852,"trade_value_usd_exp":40071521},{"year":2002,"reporter_iso":"tha","trade_value_usd_imp":40454057477,"trade_value_usd_exp":51488795017},{"year":2002,"reporter_iso":"ton","trade_value_usd_imp":35368115,"trade_value_usd_exp":6125528},{"year":2002,"reporter_iso":"tto","trade_value_usd_imp":902291393,"trade_value_usd_exp":2224670214},{"year":2002,"reporter_iso":"tun","trade_value_usd_imp":4018153604,"trade_value_usd_exp":4608549352},{"year":2002,"reporter_iso":"tur","trade_value_usd_imp":26788796498,"trade_value_usd_exp":21897917329},{"year":2002,"reporter_iso":"tuv","trade_value_usd_imp":3234834,"trade_value_usd_exp":105685},{"year":2002,"reporter_iso":"tza","trade_value_usd_imp":197742511,"trade_value_usd_exp":129202495},{"year":2002,"reporter_iso":"uga","trade_value_usd_imp":386501697,"trade_value_usd_exp":70716770},{"year":2002,"reporter_iso":"ukr","trade_value_usd_imp":4167151250,"trade_value_usd_exp":6183175900},{"year":2002,"reporter_iso":"ury","trade_value_usd_imp":591782024,"trade_value_usd_exp":600717063},{"year":2002,"reporter_iso":"usa","trade_value_usd_imp":1053982897655,"trade_value_usd_exp":565640710976},{"year":2002,"reporter_iso":"vct","trade_value_usd_imp":39574178,"trade_value_usd_exp":6986890},{"year":2002,"reporter_iso":"ven","trade_value_usd_imp":5005863233,"trade_value_usd_exp":14638938202},{"year":2002,"reporter_iso":"vnm","trade_value_usd_imp":7851205599,"trade_value_usd_exp":7246570159},{"year":2002,"reporter_iso":"wsm","trade_value_usd_imp":53909632,"trade_value_usd_exp":49603253},{"year":2002,"reporter_iso":"zaf","trade_value_usd_imp":15418460840,"trade_value_usd_exp":10645963786},{"year":2002,"reporter_iso":"zmb","trade_value_usd_imp":727154837,"trade_value_usd_exp":316017140},{"year":2002,"reporter_iso":"zwe","trade_value_usd_imp":1021682826,"trade_value_usd_exp":895741066}]'
29 | recorded_at: 2024-08-22 20:41:11 GMT
30 | recorded_with: vcr/1.2.2, webmockr/0.9.0
31 |
--------------------------------------------------------------------------------
/tests/fixtures/vcr_cassettes/chl_arg_2002_yrp.yml:
--------------------------------------------------------------------------------
1 | http_interactions:
2 | - request:
3 | method: get
4 | uri: https://api.tradestatistics.io/yrp?y=2002&r=chl&p=arg
5 | body:
6 | encoding: ''
7 | string: ''
8 | headers:
9 | User-Agent: libcurl/7.81.0 r-curl/5.0.2 crul/1.4.0
10 | Accept-Encoding: gzip, deflate
11 | Accept: application/json, text/xml, application/xml, */*
12 | response:
13 | status:
14 | status_code: '200'
15 | message: OK
16 | explanation: Request fulfilled, document follows
17 | headers:
18 | status: HTTP/1.1 200 OK
19 | server: nginx/1.18.0 (Ubuntu)
20 | date: Thu, 22 Aug 2024 20:41:18 GMT
21 | content-type: application/json
22 | transfer-encoding: chunked
23 | connection: keep-alive
24 | content-encoding: gzip
25 | body:
26 | encoding: ''
27 | file: no
28 | string: '[{"year":2002,"reporter_iso":"chl","partner_iso":"arg","trade_value_usd_imp":919280993,"trade_value_usd_exp":191070218}]'
29 | recorded_at: 2024-08-22 20:41:18 GMT
30 | recorded_with: vcr/1.2.2, webmockr/0.9.0
31 |
--------------------------------------------------------------------------------
/tests/fixtures/vcr_cassettes/chl_arg_2002_yrpc_fish.yml:
--------------------------------------------------------------------------------
1 | http_interactions:
2 | - request:
3 | method: get
4 | uri: https://api.tradestatistics.io/yrpc?y=2002&r=chl&p=arg&c=03
5 | body:
6 | encoding: ''
7 | string: ''
8 | headers:
9 | User-Agent: libcurl/7.81.0 r-curl/5.0.2 crul/1.4.0
10 | Accept-Encoding: gzip, deflate
11 | Accept: application/json, text/xml, application/xml, */*
12 | response:
13 | status:
14 | status_code: '200'
15 | message: OK
16 | explanation: Request fulfilled, document follows
17 | headers:
18 | status: HTTP/1.1 200 OK
19 | server: nginx/1.18.0 (Ubuntu)
20 | date: Thu, 22 Aug 2024 20:41:10 GMT
21 | content-type: application/json
22 | transfer-encoding: chunked
23 | connection: keep-alive
24 | content-encoding: gzip
25 | body:
26 | encoding: ''
27 | file: no
28 | string: '[{"year":2002,"reporter_iso":"chl","partner_iso":"arg","section_code":"01","commodity_code":"030484","trade_value_usd_imp":54522,"trade_value_usd_exp":247904},{"year":2002,"reporter_iso":"chl","partner_iso":"arg","section_code":"01","commodity_code":"030491","trade_value_usd_imp":31716,"trade_value_usd_exp":89539},{"year":2002,"reporter_iso":"chl","partner_iso":"arg","section_code":"01","commodity_code":"030541","trade_value_usd_imp":55,"trade_value_usd_exp":150549},{"year":2002,"reporter_iso":"chl","partner_iso":"arg","section_code":"01","commodity_code":"030719","trade_value_usd_imp":230920,"trade_value_usd_exp":351917},{"year":2002,"reporter_iso":"chl","partner_iso":"arg","section_code":"01","commodity_code":"030749","trade_value_usd_imp":95904,"trade_value_usd_exp":10563}]'
29 | recorded_at: 2024-08-22 20:41:10 GMT
30 | recorded_with: vcr/1.2.2, webmockr/0.9.0
31 |
--------------------------------------------------------------------------------
/tests/fixtures/vcr_cassettes/chl_arg_2002_yrpc_wheat.yml:
--------------------------------------------------------------------------------
1 | http_interactions:
2 | - request:
3 | method: get
4 | uri: https://api.tradestatistics.io/yrpc?y=2002&r=chl&p=arg&c=110100
5 | body:
6 | encoding: ''
7 | string: ''
8 | headers:
9 | User-Agent: libcurl/7.81.0 r-curl/5.0.2 crul/1.4.0
10 | Accept-Encoding: gzip, deflate
11 | Accept: application/json, text/xml, application/xml, */*
12 | response:
13 | status:
14 | status_code: '200'
15 | message: OK
16 | explanation: Request fulfilled, document follows
17 | headers:
18 | status: HTTP/1.1 200 OK
19 | server: nginx/1.18.0 (Ubuntu)
20 | date: Thu, 22 Aug 2024 20:41:10 GMT
21 | content-type: application/json
22 | transfer-encoding: chunked
23 | connection: keep-alive
24 | content-encoding: gzip
25 | body:
26 | encoding: ''
27 | file: no
28 | string: '[{"year":2002,"reporter_iso":"chl","partner_iso":"arg","section_code":"02","commodity_code":"110100","trade_value_usd_imp":341,"trade_value_usd_exp":76}]'
29 | recorded_at: 2024-08-22 20:41:10 GMT
30 | recorded_with: vcr/1.2.2, webmockr/0.9.0
31 |
--------------------------------------------------------------------------------
/tests/fixtures/vcr_cassettes/chl_arg_2004_yr.yml:
--------------------------------------------------------------------------------
1 | http_interactions:
2 | - request:
3 | method: get
4 | uri: https://api.tradestatistics.io/yr?y=2004&r=chl
5 | body:
6 | encoding: ''
7 | string: ''
8 | headers:
9 | User-Agent: libcurl/7.81.0 r-curl/5.0.2 crul/1.4.0
10 | Accept-Encoding: gzip, deflate
11 | Accept: application/json, text/xml, application/xml, */*
12 | response:
13 | status:
14 | status_code: '200'
15 | message: OK
16 | explanation: Request fulfilled, document follows
17 | headers:
18 | status: HTTP/1.1 200 OK
19 | server: nginx/1.18.0 (Ubuntu)
20 | date: Thu, 22 Aug 2024 20:41:17 GMT
21 | content-type: application/json
22 | transfer-encoding: chunked
23 | connection: keep-alive
24 | content-encoding: gzip
25 | body:
26 | encoding: ''
27 | file: no
28 | string: '[{"year":2004,"reporter_iso":"chl","trade_value_usd_imp":9823388774,"trade_value_usd_exp":12014727566}]'
29 | recorded_at: 2024-08-22 20:41:17 GMT
30 | recorded_with: vcr/1.2.2, webmockr/0.9.0
31 |
--------------------------------------------------------------------------------
/tests/fixtures/vcr_cassettes/chl_myt_2002_yrp.yml:
--------------------------------------------------------------------------------
1 | http_interactions:
2 | - request:
3 | method: get
4 | uri: https://api.tradestatistics.io/yrp?y=2002&r=chl&p=myt
5 | body:
6 | encoding: ''
7 | string: ''
8 | headers:
9 | User-Agent: libcurl/7.81.0 r-curl/5.0.2 crul/1.4.0
10 | Accept-Encoding: gzip, deflate
11 | Accept: application/json, text/xml, application/xml, */*
12 | response:
13 | status:
14 | status_code: '200'
15 | message: OK
16 | explanation: Request fulfilled, document follows
17 | headers:
18 | status: HTTP/1.1 200 OK
19 | server: nginx/1.18.0 (Ubuntu)
20 | date: Thu, 22 Aug 2024 20:41:12 GMT
21 | content-type: application/json
22 | transfer-encoding: chunked
23 | connection: keep-alive
24 | content-encoding: gzip
25 | body:
26 | encoding: ''
27 | file: no
28 | string: '[{"year":2002,"reporter_iso":"chl","partner_iso":"myt","observation":"No
29 | data available for these filtering parameters"}]'
30 | recorded_at: 2024-08-22 20:41:12 GMT
31 | recorded_with: vcr/1.2.2, webmockr/0.9.0
32 |
--------------------------------------------------------------------------------
/tests/testthat.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(tradestatistics)
3 |
4 | test_check("tradestatistics")
5 |
--------------------------------------------------------------------------------
/tests/testthat/helper-tradestatistics.R:
--------------------------------------------------------------------------------
1 | library(vcr)
2 | invisible(vcr::vcr_configure(dir = "../../tests/fixtures/vcr_cassettes"))
3 |
--------------------------------------------------------------------------------
/tests/testthat/test-ots_country_code.R:
--------------------------------------------------------------------------------
1 | context("country code")
2 |
3 | test_that("ots_country_code works properly for single matching", {
4 | test_country_1 <- ots_country_code("Chile")
5 | test_country_2 <- ots_country_code("CHILE")
6 | test_country_3 <- ots_country_code("Chil")
7 |
8 | expect_output(str(test_country_1), "chl")
9 | expect_output(str(test_country_2), "chl")
10 | expect_output(str(test_country_3), "chl")
11 | })
12 |
13 | test_that("ots_country_code works properly for multiple matching", {
14 | test_country_1 <- ots_country_code("Germany")
15 | test_country_2 <- ots_country_code("GERMANY")
16 | test_country_3 <- ots_country_code("all")
17 |
18 | expect_is(test_country_1, "data.frame")
19 | expect_is(test_country_2, "data.frame")
20 | expect_is(test_country_3, "data.frame")
21 |
22 | expect_equal(ncol(test_country_1), 5)
23 | expect_equal(ncol(test_country_2), 5)
24 | expect_equal(ncol(test_country_3), 5)
25 | })
26 |
27 | test_that("ots_country_code returns an error when no countryname is specified", {
28 | expect_error(ots_country_code(countryname = ""))
29 | expect_error(ots_country_code(countryname = NULL))
30 | })
31 |
32 | test_that("ots_country_code returns 0 rows when no match exists", {
33 | d <- ots_country_code(countryname = "Abc")
34 | expect_equal(nrow(d), 0)
35 | })
36 |
--------------------------------------------------------------------------------
/tests/testthat/test-ots_create_tidy_data.R:
--------------------------------------------------------------------------------
1 | context("create tidy data")
2 |
3 | # ots_create_tidy_data connects to the API and returns valid tables with a valid input ----
4 |
5 | # Mock countries test inside ots_create_tidy_data
6 |
7 | test_that("valid input + no cache = yr(p)(c) table", {
8 | skip_on_cran()
9 | vcr::use_cassette(name = "chl_arg_2002_yrpc", {
10 | # Bilateral trade Chile-Argentina at commodity level (2002)
11 | test_data <- ots_create_tidy_data(
12 | years = 2002, reporters = "chl", partners = "arg", table = "yrpc"
13 | )
14 | expect_is(test_data, "data.frame")
15 | expect_equal(ncol(test_data), 12)
16 |
17 | # Bilateral trade Chile-Argentina at aggregated level (2002)
18 | test_data <- ots_create_tidy_data(
19 | years = 2002, reporters = "chl", partners = "arg", table = "yrp"
20 | )
21 | expect_is(test_data, "data.frame")
22 | expect_equal(ncol(test_data), 7)
23 |
24 | # Chilean trade at commodity level (2002)
25 | test_data <- ots_create_tidy_data(
26 | years = 2002, reporters = "chl", table = "yrc"
27 | )
28 | expect_is(test_data, "data.frame")
29 | expect_equal(ncol(test_data), 10)
30 |
31 | # Chilean trade at aggregated level (2002)
32 | test_data <- ots_create_tidy_data(years = 2002, reporters = "chl",
33 | table = "yr")
34 | expect_is(test_data, "data.frame")
35 | expect_equal(ncol(test_data), 5)
36 |
37 | # Commodity trade at aggregated level (2002)
38 | test_data <- ots_create_tidy_data(years = 2002, table = "yc")
39 | expect_is(test_data, "data.frame")
40 | expect_equal(ncol(test_data), 8)
41 | })
42 | })
43 |
44 | test_that("valid input + cache = yrpc table", {
45 | skip_on_cran()
46 | vcr::use_cassette(name = "chl_arg_2002_yrpc_cache", {
47 | # test in memory cache
48 | test_data <- ots_create_tidy_data(
49 | years = 2002, reporters = "chl", partners = "arg", table = "yrpc",
50 | use_cache = TRUE
51 | )
52 | # test file cache
53 | test_data <- ots_create_tidy_data(
54 | years = 2002, reporters = "chl", partners = "arg", table = "yrpc",
55 | use_cache = TRUE, file = tempfile("data")
56 | )
57 | expect_is(test_data, "data.frame")
58 | expect_equal(ncol(test_data), 12)
59 | })
60 | })
61 |
62 | test_that("valid input + no cache + commodity filter = yrpc table", {
63 | skip_on_cran()
64 | vcr::use_cassette(name = "chl_arg_2002_yrpc_wheat", {
65 | test_data <- ots_create_tidy_data(
66 | years = 2002, reporters = "chl", partners = "arg", table = "yrpc",
67 | commodities = "110100"
68 | )
69 |
70 | expect_is(test_data, "data.frame")
71 | expect_equal(ncol(test_data), 12)
72 | })
73 | })
74 |
75 | test_that("valid input + no cache + group filter = yrpc table", {
76 | skip_on_cran()
77 | vcr::use_cassette(name = "chl_arg_2002_yrpc_fish", {
78 | # filter group 03 = fish and crustaceans...
79 | test_data <- ots_create_tidy_data(
80 | years = 2002, reporters = "chl", partners = "arg", table = "yrpc",
81 | commodities = "03"
82 | )
83 |
84 | expect_is(test_data, "data.frame")
85 | expect_equal(ncol(test_data), 12)
86 | })
87 | })
88 |
89 | test_that("unused commodities argument = yr table + warning", {
90 | skip_on_cran()
91 | vcr::use_cassette(name = "chl_arg_2002_yr_apple", {
92 | test_data <- expect_warning(
93 | ots_create_tidy_data(years = 2002, table = "yr", commodities = "apple")
94 | )
95 |
96 | expect_is(test_data, "data.frame")
97 | expect_equal(ncol(test_data), 5)
98 | })
99 | })
100 |
101 | test_that("valid countries/NULL = yrp table /+ warning", {
102 | skip_on_cran()
103 | vcr::use_cassette(name = "chl_all_2002_yrp", {
104 | expect_warning(
105 | ots_create_tidy_data(
106 | years = 2002, reporters = "chl", partners = NULL, table = "yrp"
107 | )
108 | )
109 |
110 | expect_warning(
111 | ots_create_tidy_data(
112 | years = 2002, reporters = NULL, partners = 'chl', table = "yrp"
113 | )
114 | )
115 | })
116 | })
117 |
118 | test_that("no API data = warning", {
119 | skip_on_cran()
120 | vcr::use_cassette(name = "chl_myt_2002_yrp", {
121 | expect_warning(
122 | ots_create_tidy_data(
123 | years = 2002, reporters = 'chl', partners = 'myt', table = "yrp"
124 | )
125 | )
126 | })
127 | })
128 |
129 | test_that("valid mixed country ISO/string = yrp table", {
130 | skip_on_cran()
131 | vcr::use_cassette(name = "chl_arg_2002_yr", {
132 | expect_s3_class(
133 | ots_create_tidy_data(
134 | years = 2002, reporters = c("Argentina","chl"), table = "yr"
135 | ),
136 | "data.frame"
137 | )
138 |
139 | expect_s3_class(
140 | ots_create_tidy_data(
141 | years = 2002, reporters = "mex", partners = c("Canada","usa"),
142 | table = "yrp"
143 | ),
144 | "data.frame"
145 | )
146 | })
147 | })
148 |
149 | test_that("wrong YR input = error + warning", {
150 | skip_on_cran()
151 |
152 | # Bilateral trade ABC-ARG fake ISO codes (2002) - Error message
153 | expect_error(
154 | expect_warning(
155 | ots_create_tidy_data(years = 2002, reporters = "abc", partners = "arg"),
156 | "After ignoring the unmatched reporter strings"
157 | )
158 | )
159 |
160 | # Bilateral trade CHL-ABC fake ISO code (2002) - Error message
161 | expect_error(
162 | expect_warning(
163 | ots_create_tidy_data(years = 2002, reporters = "chl", partners = "abc"),
164 | "After ignoring the unmatched partner strings"
165 | )
166 | )
167 |
168 | # Bilateral trade USA (1776) - Error message
169 | expect_error(
170 | ots_create_tidy_data(years = 1776, reporters = "usa", partners = "all"),
171 | "Provided that the table you requested contains a 'year' field"
172 | )
173 |
174 | # Bilateral trade Chile-Argentina with fake table (2002) - Error message
175 | expect_error(
176 | ots_create_tidy_data(years = 2002, reporters = "chl", partners = "arg",
177 | table = "abc"),
178 | "requested table does not exist"
179 | )
180 | })
181 |
182 | test_that("invalid cache/file input = error + warning", {
183 | skip_on_cran()
184 |
185 | # Incorrect parameters
186 | expect_error(
187 | expect_warning(
188 | ots_create_tidy_data(
189 | years = 2002, reporters = "arg", partners = "chl",
190 | use_cache = 200100,
191 | file = "foo.bar"
192 | ),
193 | "After ignoring the unmatched reporter strings"
194 | )
195 | )
196 |
197 | expect_error(
198 | expect_warning(
199 | ots_create_tidy_data(
200 | years = 2002, reporters = "arg", partners = "chl",
201 | use_cache = TRUE,
202 | file = 200100
203 | ),
204 | "After ignoring the unmatched reporter strings"
205 | )
206 | )
207 | })
208 |
209 | test_that("non-existing product code = error", {
210 | skip_on_cran()
211 |
212 | expect_error(
213 | ots_create_tidy_data(
214 | years = 2002, reporters = "chl", partners = "arg", table = "yrpc",
215 | commodities = "0000"
216 | )
217 | )
218 | })
219 |
220 | test_that("non-existing product string = error + warning", {
221 | skip_on_cran()
222 |
223 | vcr::use_cassette(name = "chl_arg_2002_yrpc", {
224 | expect_error(
225 | expect_warning(
226 | ots_create_tidy_data(
227 | years = 2002, reporters = "chl", partners = "arg", table = "yrpc",
228 | commodities = "kriptonite"
229 | )
230 | )
231 | )
232 | })
233 | })
234 |
235 | test_that("no country match = error", {
236 | skip_on_cran()
237 |
238 | expect_error(
239 | ots_create_tidy_data(
240 | years = 2002, reporters = "Wakanda", table = "yr"
241 | )
242 | )
243 |
244 | expect_error(
245 | ots_create_tidy_data(
246 | years = 2002, reporters = "usa", partners = "Wakanda", table = "yrp"
247 | )
248 | )
249 |
250 | expect_error(
251 | ots_create_tidy_data(
252 | years = 2002, reporters = "", table = "yr"
253 | )
254 | )
255 | })
256 |
257 | test_that("wrong optional parameters = error", {
258 | skip_on_cran()
259 |
260 | # Incorrect parameters
261 | expect_error(
262 | ots_create_tidy_data(
263 | years = 2002, reporters = "arg", partners = "chl",
264 | max_attempts = 0
265 | )
266 | )
267 |
268 | expect_error(
269 | ots_create_tidy_data(
270 | years = 2002, reporters = "arg", partners = "chl",
271 | use_localhost = 0
272 | )
273 | )
274 | })
275 |
--------------------------------------------------------------------------------
/tests/testthat/test-ots_inflation_adjustment.R:
--------------------------------------------------------------------------------
1 | context("inflation adjustment")
2 |
3 | test_that("ots_gdp_deflator_adjustment adjusts the data for yrpc", {
4 | skip_on_cran()
5 | vcr::use_cassette(name = "chl_arg_2004_yrpc", {
6 | # Bilateral trade Chile-Argentina at commodity level (1964)
7 | test_data <- ots_create_tidy_data(
8 | years = 2004, reporters = "chl", partners = "arg", table = "yrpc"
9 | )
10 |
11 | test_data_adjusted_backwards <- ots_gdp_deflator_adjustment(test_data, reference_year = 2002)
12 |
13 | test_data_adjusted_forwards <- ots_gdp_deflator_adjustment(test_data, reference_year = 2006)
14 |
15 | test_data_adjusted_same <- ots_gdp_deflator_adjustment(test_data, reference_year = 2004)
16 |
17 | expect_is(test_data_adjusted_backwards, "data.frame")
18 | expect_equal(ncol(test_data_adjusted_backwards), 14)
19 |
20 | expect_is(test_data_adjusted_forwards, "data.frame")
21 | expect_equal(ncol(test_data_adjusted_forwards), 14)
22 |
23 | expect_is(test_data_adjusted_same, "data.frame")
24 | expect_equal(ncol(test_data_adjusted_same), 14)
25 | })
26 | })
27 |
28 | test_that("ots_gdp_deflator_adjustment adjusts the data for yr", {
29 | skip_on_cran()
30 | vcr::use_cassette(name = "chl_arg_2004_yr", {
31 | # Bilateral trade Chile-Argentina at commodity level (1964)
32 | test_data <- ots_create_tidy_data(
33 | years = 2004, reporters = "chl", partners = "arg", table = "yr"
34 | )
35 |
36 | test_data_adjusted_backwards <- ots_gdp_deflator_adjustment(test_data, reference_year = 2000)
37 |
38 | expect_is(test_data_adjusted_backwards, "data.frame")
39 | expect_equal(ncol(test_data_adjusted_backwards), 7)
40 | })
41 | })
42 |
43 | test_that("ots_gdp_deflator_adjustment fails if the parameters are null or out of range", {
44 | skip_on_cran()
45 | vcr::use_cassette(name = "chl_arg_2002_yrp", {
46 | # Bilateral trade Chile-Argentina at commodity level (1964)
47 | test_data <- ots_create_tidy_data(
48 | years = 2002, reporters = "chl", partners = "arg", table = "yrp"
49 | )
50 |
51 | # truncated message as it changes when the API has more years
52 | expect_error(
53 | test_data_adjusted <- ots_gdp_deflator_adjustment(test_data, reference_year = 1776),
54 | "The reference year must be numeric and contained within ots_gdp_deflator years range"
55 | )
56 |
57 | expect_error(
58 | ots_gdp_deflator_adjustment(trade_data = NULL, reference_year = 1776),
59 | "The input data cannot be NULL."
60 | )
61 |
62 | expect_error(
63 | ots_gdp_deflator_adjustment(trade_data = test_data, reference_year = NULL),
64 | "The reference year cannot be NULL."
65 | )
66 | })
67 | })
68 |
--------------------------------------------------------------------------------
/tests/testthat/test-ots_strings_processing.R:
--------------------------------------------------------------------------------
1 | context("strings processing")
2 |
3 | test_that("ots_commodity_code works properly for a partial product string matching", {
4 | test_product <- ots_commodity_code(commodity = "fruit")
5 |
6 | expect_is(test_product, "data.frame")
7 | expect_equal(nrow(test_product),89)
8 | expect_equal(ncol(test_product),2)
9 | })
10 |
11 | test_that("ots_commodity_code returns 0 rows for a non-existing product match", {
12 | d <- ots_commodity_code(commodity = "adamantium")
13 | expect_equal(nrow(d),0)
14 | })
15 |
16 | test_that("ots_commodity_code returns an error when no product is specified", {
17 | expect_error(ots_commodity_code(commodity = ""))
18 | })
19 |
20 | test_that("ots_commodity_code works properly for a partial section string matching", {
21 | test_section <- ots_commodity_code(section = "vegetable")
22 |
23 | expect_is(test_section, "data.frame")
24 | expect_equal(ncol(test_section),2)
25 | expect_equal(nrow(test_section),2)
26 | })
27 |
28 | test_that("ots_commodity_code return 0 rows for a non-existing section match", {
29 | d <- ots_commodity_code(section = "headphones and speakers")
30 | expect_equal(nrow(d),0)
31 | })
32 |
33 | test_that("ots_commodity_code returns an error when no section is specified", {
34 | expect_error(ots_commodity_code(section = ""))
35 | })
36 |
37 | test_that("ots_commodity_code works ok for both specified product and section", {
38 | test_both <- ots_commodity_code(commodity = "potato", section = "vegetable")
39 |
40 | expect_is(test_both, "data.frame")
41 | expect_equal(ncol(test_both),5)
42 | expect_equal(nrow(test_both),8)
43 | })
44 |
45 | test_that("ots_commodity_code fails with NULL product/section", {
46 | expect_error(ots_commodity_code(commodity = NULL, section = NULL))
47 | })
48 |
49 | test_that("ots_commodity_code fails when both arguments are empty", {
50 | expect_error(ots_commodity_code(commodity = "", section = ""))
51 | })
52 |
53 | test_that("ots_commodity_code returns error or no results for strange inputs", {
54 | # this shall fail
55 | expect_error(ots_commodity_code(commodity = "1234", section = "1234"))
56 |
57 | # this shall return an empty data.frame
58 | d <- ots_commodity_code(commodity = "kriptonite", section = "adamantium")
59 | expect_is(d, "data.frame")
60 | expect_equal(nrow(d),0)
61 | })
62 |
--------------------------------------------------------------------------------
/tradestatistics.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 | PackageRoxygenize: rd,collate,namespace,vignette
19 |
--------------------------------------------------------------------------------
/vignettes/basic-usage.R:
--------------------------------------------------------------------------------
1 | ## ----setup, include = FALSE---------------------------------------------------
2 | knitr::opts_chunk$set(
3 | cache = FALSE,
4 | collapse = TRUE,
5 | message = FALSE,
6 | comment = "#>"
7 | )
8 |
9 | ## ----pkgs---------------------------------------------------------------------
10 | library(tradestatistics)
11 | library(tibble)
12 |
13 | ## ----tables, eval = T---------------------------------------------------------
14 | as_tibble(ots_tables)
15 |
16 | ## ----countries, eval = T------------------------------------------------------
17 | as_tibble(ots_countries)
18 |
19 | ## ----commodities, eval = T----------------------------------------------------
20 | as_tibble(ots_commodities)
21 |
22 | ## ----inflation, eval = T------------------------------------------------------
23 | as_tibble(ots_gdp_deflator)
24 |
25 | ## ----country_code-------------------------------------------------------------
26 | # Single match with no replacement
27 | as_tibble(ots_country_code("Chile"))
28 |
29 | # Single match with replacement
30 | as_tibble(ots_country_code("America"))
31 |
32 | # Double match with no replacement
33 | as_tibble(ots_country_code("Germany"))
34 |
35 | ## ----commodity_code2----------------------------------------------------------
36 | as_tibble(ots_commodity_code(commodity = " ShEEp ", section = " mEaT "))
37 |
38 | ## ----yrpc1, eval = F----------------------------------------------------------
39 | # yrpc <- ots_create_tidy_data(
40 | # years = 2019,
41 | # reporters = "chl",
42 | # partners = "arg",
43 | # table = "yrpc"
44 | # )
45 | #
46 | # as_tibble(yrpc)
47 |
48 | ## ----yrpc3, eval = F----------------------------------------------------------
49 | # # Note that here I'm passing Peru and not per which is the ISO code for Peru
50 | # # The same applies to Brazil
51 | # yrpc2 <- ots_create_tidy_data(
52 | # years = 2018:2019,
53 | # reporters = c("chl", "Peru", "bol"),
54 | # partners = c("arg", "Brazil"),
55 | # commodities = c("01", "food"),
56 | # table = "yrpc"
57 | # )
58 |
59 | ## ----yrp3, eval = F-----------------------------------------------------------
60 | # yrp <- ots_create_tidy_data(
61 | # years = 2018:2019,
62 | # reporters = c("chl", "per"),
63 | # partners = "arg",
64 | # table = "yrp"
65 | # )
66 |
67 | ## ----yrc2, eval = F-----------------------------------------------------------
68 | # yrc <- ots_create_tidy_data(
69 | # years = 2019,
70 | # reporters = "chl",
71 | # commodities = "010121",
72 | # table = "yrc"
73 | # )
74 |
75 | ## ----yr2, eval = F------------------------------------------------------------
76 | # yr <- ots_create_tidy_data(
77 | # years = 2018:2019,
78 | # reporters = c("chl", "arg", "per"),
79 | # table = "yr"
80 | # )
81 |
82 | ## ----yc1, eval = F------------------------------------------------------------
83 | # yc <- ots_create_tidy_data(
84 | # years = 2019,
85 | # table = "yc"
86 | # )
87 |
88 | ## ----yc2, eval = F------------------------------------------------------------
89 | # yc2 <- ots_create_tidy_data(
90 | # years = 2019,
91 | # commodities = "010121",
92 | # table = "yc"
93 | # )
94 |
95 | ## ----inflation2, eval=FALSE---------------------------------------------------
96 | # inflation <- ots_gdp_deflator_adjustment(yr, reference_year = 2000)
97 | # as_tibble(inflation)
98 |
99 |
--------------------------------------------------------------------------------
/vignettes/basic-usage.Rmd:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Basic usage"
3 | author: "Mauricio Vargas S."
4 | date: "`r Sys.Date()`"
5 | output: rmarkdown::html_vignette
6 | vignette: >
7 | %\VignetteIndexEntry{Basic usage}
8 | %\VignetteEngine{knitr::rmarkdown}
9 | %\VignetteEncoding{UTF-8}
10 | ---
11 |
12 | ```{r setup, include = FALSE}
13 | knitr::opts_chunk$set(
14 | cache = FALSE,
15 | collapse = TRUE,
16 | message = FALSE,
17 | comment = "#>"
18 | )
19 | ```
20 |
21 | # Introduction
22 |
23 | This vignette explains the functions within this package. The idea is to show how this package simplifies obtaining data from (api.tradestatistics.io)[https://api.tradestatistics.io].
24 |
25 | To improve the presentation of the tables I shall use `tibble` besides `tradestatistics`.
26 | ```{r pkgs}
27 | library(tradestatistics)
28 | library(tibble)
29 | ```
30 |
31 | # Package data
32 |
33 | ## Available tables
34 |
35 | Provided that this package obtains data from an API, it is useful to know which tables can be accessed:
36 |
37 | ```{r tables, eval = T}
38 | as_tibble(ots_tables)
39 | ```
40 |
41 | You might notice the tables have a pattern. The letters indicate the presence of columns that account for the level of detail in the data:
42 |
43 | * `y`: *y*ear column.
44 | * `r`: *r*eporter column
45 | * `p`: *p*artner column
46 | * `c`: *c*ommodity column
47 |
48 | The most aggregated table is `yr` which basically says how many dollars each country exports and imports for a given year.
49 |
50 | The less aggregated table is `yrpc` which says how many dollars of each of the 1,242 commodities from the Harmonized System each country exports to other countries and imports from other countries.
51 |
52 | For the complete detail you can check [tradestatistics.io](https://tradestatistics.io).
53 |
54 | ## Country codes
55 |
56 | The Package Functions section explains that you don't need to memorize all ISO codes. The functions within this package are designed to match strings (i.e. "United States" or "America") to valid ISO codes (i.e. "USA").
57 |
58 | Just as a reference, the table with all valid ISO codes can be accessed by running this:
59 |
60 | ```{r countries, eval = T}
61 | as_tibble(ots_countries)
62 | ```
63 |
64 | ## Commodity codes
65 |
66 | The Package Functions section explains that you don't need to memorize all HS codes. The functions within this package are designed to match strings (i.e. "apple") to valid HS codes (i.e. "0808").
67 |
68 | ```{r commodities, eval = T}
69 | as_tibble(ots_commodities)
70 | ```
71 |
72 | ## Inflation data
73 |
74 | This table is provided to be used with `ots_gdp_deflator_adjustment()`.
75 |
76 | ```{r inflation, eval = T}
77 | as_tibble(ots_gdp_deflator)
78 | ```
79 |
80 | # Package functions
81 |
82 | ## Country code
83 |
84 | The end user can use this function to find an ISO code by providing a country name. This works by implementing partial search.
85 |
86 | Basic examples:
87 | ```{r country_code}
88 | # Single match with no replacement
89 | as_tibble(ots_country_code("Chile"))
90 |
91 | # Single match with replacement
92 | as_tibble(ots_country_code("America"))
93 |
94 | # Double match with no replacement
95 | as_tibble(ots_country_code("Germany"))
96 | ```
97 |
98 | The function `ots_country_code()` is used by `ots_create_tidy_data()` in a way that you can pass parameters like `ots_create_tidy_data(... reporters = "Chile" ...)` and it will automatically replace your input for a valid ISO in case there is a match. This will be covered in detail in the Trade Data section.
99 |
100 | ## Commodity code
101 |
102 | The end user can find a code or a set of codes by looking for keywords for commodities or groups. The function `ots_commodity_code()` allows to search from the official commodities and groups in the Harmonized system:
103 | ```{r commodity_code2}
104 | as_tibble(ots_commodity_code(commodity = " Horse ", section = " ANIMAL "))
105 | ```
106 |
107 | ## Trade data
108 |
109 | This function downloads data for a single year and needs (at least) some filter parameters according to the query type.
110 |
111 | Here we cover aggregated tables to describe the usage.
112 |
113 | ### Bilateral trade at commodity level (Year - Reporter - Partner - Commodity Code)
114 |
115 | If we want Chile-Argentina bilateral trade at community level in 2019:
116 | ```{r yrpc1, eval = F}
117 | yrpc <- ots_create_tidy_data(
118 | years = 2019,
119 | reporters = "chl",
120 | partners = "arg",
121 | table = "yrpc"
122 | )
123 |
124 | as_tibble(yrpc)
125 | ```
126 |
127 | We can pass two years or more, several reporters/partners, and filter by commodities with exact codes or code matching based on keywords:
128 | ```{r yrpc3, eval = F}
129 | # Note that here I'm passing Peru and not per which is the ISO code for Peru
130 | # The same applies to Brazil
131 | yrpc2 <- ots_create_tidy_data(
132 | years = 2018:2019,
133 | reporters = c("chl", "Peru", "bol"),
134 | partners = c("arg", "Brazil"),
135 | commodities = c("01", "food"),
136 | table = "yrpc"
137 | )
138 | ```
139 |
140 | The `yrpc` table returns some fields that deserve an explanation which can be seen at [tradestatistics.io](https://tradestatistics.io). This example is interesting because "01" return a set of commodities (all commodities starting with 01, which is the commodity group "Animals; live"), but "food" return all commodities with a matching description ("1601", "1806", "1904", etc.). In addition, not all the requested commodities are exported from each reporter to each partner, therefore a warning is returned.
141 |
142 | ### Bilateral trade at aggregated level (Year - Reporter - Partner)
143 |
144 | If we want Chile-Argentina bilateral trade at aggregated level in 2018 and 2019:
145 | ```{r yrp3, eval = F}
146 | yrp <- ots_create_tidy_data(
147 | years = 2018:2019,
148 | reporters = c("chl", "per"),
149 | partners = "arg",
150 | table = "yrp"
151 | )
152 | ```
153 |
154 | This table accepts different years, reporters and partners just like `yrpc`.
155 |
156 | ### Reporter trade at commodity level (Year - Reporter - Commodity Code)
157 |
158 | If we want Chilean trade at commodity level in 2019 with respect to commodity "010121" which means "Horses; live, pure-bred breeding animals":
159 | ```{r yrc2, eval = F}
160 | yrc <- ots_create_tidy_data(
161 | years = 2019,
162 | reporters = "chl",
163 | commodities = "010121",
164 | table = "yrc"
165 | )
166 | ```
167 |
168 | This table accepts different years, reporters and commodity codes just like `yrpc`.
169 |
170 | All the variables from this table are documented at [tradestatistics.io](https://tradestatistics.io).
171 |
172 | ### Reporter trade at aggregated level (Year - Reporter)
173 |
174 | If we want the aggregated trade of Chile, Argentina and Peru in 2018 and 2019:
175 | ```{r yr2, eval = F}
176 | yr <- ots_create_tidy_data(
177 | years = 2018:2019,
178 | reporters = c("chl", "arg", "per"),
179 | table = "yr"
180 | )
181 | ```
182 |
183 | This table accepts different years and reporters just like `yrpc`.
184 |
185 | All the variables from this table are documented at [tradestatistics.io](https://tradestatistics.io).
186 |
187 | ### Commodity trade at aggregated level (Year - Commodity Code)
188 |
189 | If we want all commodities traded in 2019:
190 | ```{r yc1, eval = F}
191 | yc <- ots_create_tidy_data(
192 | years = 2019,
193 | table = "yc"
194 | )
195 | ```
196 |
197 | If we want the traded values of the commodity "010121" which means "Horses; live, pure-bred breeding animals" in 2019:
198 | ```{r yc2, eval = F}
199 | yc2 <- ots_create_tidy_data(
200 | years = 2019,
201 | commodities = "010121",
202 | table = "yc"
203 | )
204 | ```
205 |
206 | This table accepts different years just like `yrpc`.
207 |
208 | ## Inflation adjustment
209 |
210 | Taking the `yr` table from above, we can use `ots_gdp_deflator_adjustment()` to convert dollars from 2018 and 2019 to dollars of 2000:
211 |
212 | ```{r inflation2, eval=FALSE}
213 | inflation <- ots_gdp_deflator_adjustment(yr, reference_year = 2000)
214 | as_tibble(inflation)
215 | ```
216 |
--------------------------------------------------------------------------------