Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 59a4455
Showing
42 changed files
with
4,579 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
Package: tradestatistics | ||
Type: Package | ||
Title: Open Trade Statistics API Wrapper and Utility Program | ||
Version: 0.1 | ||
Authors@R: | ||
c( | ||
person(given = "Mauricio", | ||
family = "Vargas", | ||
role = c("aut", "cre", "cph"), | ||
email = "mvargas@dcc.uchile.cl", | ||
comment = c(ORCID = "0000-0003-1017-7574")), | ||
person(given = "Joshua", | ||
family = "Kunst", | ||
role = "ctb"), | ||
person(given = "Emily", | ||
family = "Riederer", | ||
role = "rev"), | ||
person(given = "Mark", | ||
family = "Padgham", | ||
role = "rev", | ||
comment = c(ORCID = "0000-0003-1017-7574")), | ||
person(given = "Amanda", | ||
family = "Dobbyn", | ||
role = "rev"), | ||
person(given = "Jorge", | ||
family = "Cimentada", | ||
role = "rev"), | ||
person(family = "United Nations International Trade Statistics Database", | ||
role = "dtc"), | ||
person(family = "Center for International Development at Harvard University", | ||
role = "dtc"), | ||
person(family = "The Observatory of Economic Complexity", | ||
role = "dtc") | ||
) | ||
URL: https://ropensci.github.io/tradestatistics | ||
BugReports: https://github.com/ropensci/tradestatistics/issues | ||
Description: Access Open Trade Statistics API from R to download international trade data. | ||
License: GPL-3 | ||
LazyData: TRUE | ||
Depends: R (>= 3.2) | ||
Imports: rlang, magrittr, dplyr, stringr, crul, purrr, jsonlite | ||
RoxygenNote: 6.1.1 | ||
Suggests: knitr, rmarkdown, testthat, styler, pkgdown, vcr | ||
VignetteBuilder: knitr | ||
Encoding: UTF-8 | ||
NeedsCompilation: no | ||
Packaged: 2019-04-05 15:49:57 UTC; pacha | ||
Author: Mauricio Vargas [aut, cre, cph] | ||
(<https://orcid.org/0000-0003-1017-7574>), | ||
Joshua Kunst [ctb], | ||
Emily Riederer [rev], | ||
Mark Padgham [rev] (<https://orcid.org/0000-0003-1017-7574>), | ||
Amanda Dobbyn [rev], | ||
Jorge Cimentada [rev], | ||
United Nations International Trade Statistics Database [dtc], | ||
Center for International Development at Harvard University [dtc], | ||
The Observatory of Economic Complexity [dtc] | ||
Maintainer: Mauricio Vargas <mvargas@dcc.uchile.cl> | ||
Repository: CRAN | ||
Date/Publication: 2019-04-06 11:30:03 UTC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
97ddfabe6a5e219636c56c01ef2a82dd *DESCRIPTION | ||
ea4081e6e72a2a058aa1873bcf89af34 *NAMESPACE | ||
ba361b21a9451a280a5129c9b3d2d268 *R/ots_country_code.R | ||
815cf341593ff530791eacea1d6f15b2 *R/ots_create_tidy_data.R | ||
a6963770544e526412a3b8eba575a502 *R/ots_product_code.R | ||
b184364fb4f3425c46e4f119b9d0f1ec *R/ots_read_from_api.R | ||
b4fe12876c37f8a22cde06e9701eecf0 *R/tradestatistics-package.R | ||
f24db368a422b880b517ba396251ddde *build/vignette.rds | ||
fcdf4455b42b8f177734e96605bef82e *data/ots_attributes_communities.rda | ||
11b53c2910685637392d25cf9faaefdb *data/ots_attributes_countries.rda | ||
fd177f7e7ec81ffcf0b47b7c99e47f22 *data/ots_attributes_product_shortnames.rda | ||
3fbd5ce97b3b91938a86fc548cc170e7 *data/ots_attributes_products.rda | ||
744dd5a340d0f469e1564b6cd59f48f7 *data/ots_attributes_tables.rda | ||
566d59ebe17e08f9647a77502c464016 *inst/REFERENCES.bib | ||
fec001b7bf36de5738e0ee722c3ea629 *inst/doc/basic-usage.R | ||
f0dcb11aab1c2b54f475ad275a8389a4 *inst/doc/basic-usage.Rmd | ||
7e6f9fef6cd7ac3908003ed8ede30910 *inst/doc/basic-usage.html | ||
339143c8b92da372dbe892d70aaac6c8 *inst/doc/creating-datasets.R | ||
ab13354e508c667e1da8b116e345c79b *inst/doc/creating-datasets.Rmd | ||
023455196c3c173f213a6f8b31ec1eaa *inst/doc/creating-datasets.html | ||
a6cb9b3453774f0e9ca6555e170f87f4 *inst/paper.md | ||
b3c8e8bdd63298aad286aed41ec8ee0f *man/ots_attributes_communities.Rd | ||
9b959e4a7025343fed095d8be3dd9bb3 *man/ots_attributes_countries.Rd | ||
d68407c21b283a79d601ee69f61a389c *man/ots_attributes_product_shortnames.Rd | ||
a00639fb5d0527aeaf87321626efa6c1 *man/ots_attributes_products.Rd | ||
ae22a727084cca4c767a58578cb1ad0d *man/ots_attributes_tables.Rd | ||
b28f3bbc7866ba6eb61c1edbe285dfcc *man/ots_country_code.Rd | ||
32a93d5675006f83299f90b716c1a530 *man/ots_create_tidy_data.Rd | ||
e5eff13ad6b7c8d65508c3150aa0ddf9 *man/ots_product_code.Rd | ||
c8248e627b33bbba83d1c7816871e977 *man/ots_read_from_api.Rd | ||
014ee92130e057ba8e5c71842be9e33e *man/tradestatistics-package.Rd | ||
dda31577ec667f2f7d5f94759068a4aa *tests/fixtures/vcr_cassettes/chl_arg_1965.yml | ||
6f0d66d620db2d481bc9a4e4349c10e7 *tests/testthat.R | ||
9b1c461abf5c5354a25129ff483c5e07 *tests/testthat/helper-tradestatistics.R | ||
b116cb0de3f58f200bc01c5b590a7511 *tests/testthat/test-ots_country_code.R | ||
4048de4a096526ab0787d483cacf6d1b *tests/testthat/test-ots_create_tidy_data.R | ||
89499185bade1abba357c9ca100ccad1 *tests/testthat/test-ots_product_code.R | ||
f0dcb11aab1c2b54f475ad275a8389a4 *vignettes/basic-usage.Rmd | ||
4317f0ed4eb597cc8ed47a3b22799aff *vignettes/basic-usage.md | ||
ab13354e508c667e1da8b116e345c79b *vignettes/creating-datasets.Rmd | ||
12541f962f9b0aacf85978b076437c06 *vignettes/creating-datasets.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(ots_country_code) | ||
export(ots_create_tidy_data) | ||
export(ots_product_code) | ||
importFrom(crul,HttpClient) | ||
importFrom(dplyr,as_tibble) | ||
importFrom(dplyr,bind_rows) | ||
importFrom(dplyr,distinct) | ||
importFrom(dplyr,everything) | ||
importFrom(dplyr,filter) | ||
importFrom(dplyr,left_join) | ||
importFrom(dplyr,mutate) | ||
importFrom(dplyr,rename) | ||
importFrom(dplyr,select) | ||
importFrom(dplyr,starts_with) | ||
importFrom(jsonlite,fromJSON) | ||
importFrom(magrittr,"%<>%") | ||
importFrom(magrittr,"%>%") | ||
importFrom(purrr,as_vector) | ||
importFrom(purrr,map_df) | ||
importFrom(rlang,sym) | ||
importFrom(rlang,syms) | ||
importFrom(stringr,str_detect) | ||
importFrom(stringr,str_squish) | ||
importFrom(stringr,str_to_lower) | ||
importFrom(stringr,str_trim) | ||
importFrom(utils,data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#' String matching of official country names and ISO-3 codes according to | ||
#' the United Nations nomenclature | ||
#' @description This function takes a text string and searches within the | ||
#' package data for a country code in the context of valid API country codes. | ||
#' @param countryname A text string such as "Chile", "CHILE" or "CHL". | ||
#' @return A single character if there is a exact match (e.g. | ||
#' \code{ots_country_code("Chile")}) or a tibble in case of multiple matches | ||
#' (e.g. \code{ots_country_code("Germany")}) | ||
#' @importFrom magrittr %>% | ||
#' @importFrom dplyr select filter | ||
#' @importFrom rlang sym | ||
#' @importFrom purrr as_vector | ||
#' @importFrom stringr str_detect str_to_lower str_trim str_squish | ||
#' @export | ||
#' @examples | ||
#' ots_country_code("Chile ") | ||
#' ots_country_code("america") | ||
#' ots_country_code("UNITED STATES") | ||
#' ots_country_code(" united_") | ||
#' @keywords functions | ||
|
||
ots_country_code <- function(countryname = NULL) { | ||
if(is.null(countryname)) { | ||
stop( | ||
" | ||
countryname can't be NULL | ||
try with a quoted text string (e.g. ots_country_code(\"chi\")) | ||
" | ||
) | ||
} else { | ||
countryname <- iconv(countryname, to = "ASCII//TRANSLIT", sub = " ") | ||
countryname <- stringr::str_replace_all(countryname, "[^[:alpha:]]", " ") | ||
countryname <- stringr::str_squish(countryname) | ||
countryname <- stringr::str_trim(countryname) | ||
} | ||
|
||
if(nchar(countryname) < 1) { | ||
stop( | ||
" | ||
countryname can't have zero characters after removing numbers, | ||
special symbols and multiple spaces | ||
try with a quoted text string (e.g. ots_country_code(\"chi\")) | ||
" | ||
) | ||
} else { | ||
countryname <- stringr::str_to_lower(countryname) | ||
} | ||
|
||
countryname <- switch(countryname, | ||
"us" = "usa", | ||
"america" = "usa", | ||
"united states" = "usa", | ||
"united states of america" = "usa", | ||
"uk" = "united kingdom", | ||
"england" = "united kingdom", | ||
"scotland" = "united kingdom", | ||
"holland" = "netherlands", | ||
"myanmar" = "burma", | ||
"persia" = "iran", | ||
"siam" = "thailand", | ||
"indochina" = "vietnam", | ||
"rhodesia" = "zimbabwe", | ||
"british honduras" = "belice", | ||
"bengal" = "bangladesh", | ||
"east pakistan" = "bangladesh", | ||
"zaire" = "democratic republic of the congo", | ||
countryname | ||
) | ||
|
||
countrycode <- tradestatistics::ots_attributes_countries %>% | ||
dplyr::filter( | ||
stringr::str_detect( | ||
stringr::str_to_lower(!!sym("country_fullname_english")), countryname | ||
) | ||
) | ||
|
||
if (length(countrycode) == 0) { | ||
message( | ||
"There is no match for your search. Please check the spelling or | ||
explore the countries table provided within this package." | ||
) | ||
} | ||
|
||
return(countrycode) | ||
} |
Oops, something went wrong.