Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge changes from review into main #74

Merged
merged 30 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3458392
edited the help file in utils in order to specify all possible values…
datapumpernickel Dec 15, 2023
900bc92
renamed some arguments to ct_get_ref_table so they are more intuitive
datapumpernickel Dec 15, 2023
234d616
new help file for changed arguments to ct_get_ref_table
datapumpernickel Dec 15, 2023
5efeca4
added a paragraph on using ct_get_ref_table in the vignette
datapumpernickel Dec 15, 2023
d9f617d
implement extra_params in build_request
datapumpernickel Dec 15, 2023
f1cfaa4
implementing mode of transport as text, instead of id, extra_params i…
datapumpernickel Dec 15, 2023
006abbc
reflect changes in arguments in help file of ct_get_data, ad more des…
datapumpernickel Dec 15, 2023
e170757
implemented locae unspecific date parsing in last_modified date for u…
datapumpernickel Dec 15, 2023
8a230ed
added new mock files
datapumpernickel Dec 15, 2023
2c6cb25
adjust tests to changes
datapumpernickel Dec 15, 2023
eee4b80
deleted dependency vcr, which was unnecessary all along
datapumpernickel Dec 15, 2023
ca131ac
added help for extra_param
datapumpernickel Dec 15, 2023
2b4cf65
nord for replace_month function
datapumpernickel Dec 15, 2023
b3dc1ce
add correct mock-dir with simplify=F so that headers are recorded
datapumpernickel Dec 15, 2023
6e4b4e0
help rd files updates
datapumpernickel Dec 15, 2023
9e714f4
deleted rest library call to vcr and unreferenced variable in check_mot
datapumpernickel Dec 15, 2023
b662fa4
implemented ct_get_ref_table for flow_direction, changed input parame…
datapumpernickel Dec 17, 2023
c3af057
changed flow_direction parameter to case-insensitive to avoid confusi…
datapumpernickel Dec 17, 2023
c190e89
implement 'everything' as an alterantive to 'NULL" in documentation, …
datapumpernickel Dec 21, 2023
43e0728
added reviewers in Description
datapumpernickel Dec 22, 2023
a2c014a
added vignette on transitioning from old comtradr
datapumpernickel Dec 22, 2023
6d291ee
build vignette with example for large data
datapumpernickel Dec 22, 2023
0e059c7
get data for vignettes
datapumpernickel Dec 22, 2023
01f19eb
more word on wordlist for spell checking
datapumpernickel Dec 22, 2023
e70be60
updated vignettes with some spelluing and transition info
datapumpernickel Dec 22, 2023
b353e63
more details on authentication
datapumpernickel Dec 22, 2023
7916019
styler corrections
datapumpernickel Dec 22, 2023
1992476
lines longer than 80 characters
datapumpernickel Dec 22, 2023
94f0da2
more tests for check_params, fix for motcode where something qwas dup…
datapumpernickel Dec 22, 2023
bbf6a83
update on NULL parameteres documentation
datapumpernickel Dec 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,22 @@ Authors@R: c(
role = "rev",
comment = c(ORCID = "0000-0002-3915-0618",
"Alicia reviewed the package for rOpenSci,
see https://github.com/ropensci/onboarding/issues/141")),
see https://github.com/ropensci/onboarding/issues/141")),
person("Rafael", "Hellwig",
role = "rev",
comment = c(ORCID = "0000-0002-3092-3493",
"Rafael reviewed the package for rOpenSci,
see https://github.com/ropensci/onboarding/issues/141")),
see https://github.com/ropensci/onboarding/issues/141")),
person("Ernest", "Guevarra",
role = "rev",
comment = c(ORCID = "0000-0002-4887-4415",
"Ernest reviewed the package for rOpenSci,
see https://github.com/ropensci/software-review/issues/613")),
person("Nicholas", "Potter",
role = "rev",
comment = c(ORCID = "0000-0002-3410-3732",
"Nicholas reviewed the package for rOpenSci,
see https://github.com/ropensci/software-review/issues/613")),
person("Juergen", "Amann", role=c("ctb")))
Description: Interface with and extract data from the United Nations Comtrade
API <https://comtradeplus.un.org/>. Comtrade provides country level shipping
Expand All @@ -49,8 +59,7 @@ Suggests:
knitr,
rmarkdown,
spelling,
testthat (>= 3.0.0),
vcr
testthat (>= 3.0.0)
License: GPL-3
Encoding: UTF-8
LazyData: true
Expand Down
59 changes: 34 additions & 25 deletions R/ct_build_request.R
Original file line number Diff line number Diff line change
@@ -1,38 +1,47 @@
#' Build a valid request object from the checked parameters
#'
#' This is an internal function takes the necessary parameters from `ct_check_params()`
#' and creates a httr2 request to be performed. This request can then be used in a second function, `ct_perform_request()` to actually return the data.
#' It is called internally ct `ct_get_data()`
#' This is an internal function takes the necessary parameters
#' from `ct_check_params()` and creates a httr2 request to be performed.
#' This request can then be used in a second function, `ct_perform_request()`
#' to actually return the data. It is called internally ct `ct_get_data()`
#'
#' @param params a named vector of parameters for the comtrade request, result from `ct_check_params()`.
#' @param params a named vector of parameters for the comtrade request,
#' result from `ct_check_params()`.
#'
#' @examplesIf interactive()
#' # Build request from checked parameters
#' comtradr:::ct_build_request(comtradr:::ct_check_params(type = 'goods',
#' frequency = 'A',
#' commodity_classification = 'HS',
#' commodity_code = 'TOTAL',
#' flow_direction = 'all',
#' reporter = 'all',
#' partner = 'World',
#' start_date = 2020,
#' end_date = 2022,
#' process = TRUE,
#' tidy_cols = TRUE,
#' verbose = FALSE,
#' primary_token = 'xxxx',
#' mode_of_transport = '0',
#' partner_2 = 'World',
#' customs_code ='C00',
#' update = FALSE ))
#' comtradr:::ct_build_request(comtradr:::ct_check_params(
#' type = "goods",
#' frequency = "A",
#' commodity_classification = "HS",
#' commodity_code = "TOTAL",
#' flow_direction = "all",
#' reporter = "all",
#' partner = "World",
#' start_date = 2020,
#' end_date = 2022,
#' process = TRUE,
#' tidy_cols = TRUE,
#' verbose = FALSE,
#' primary_token = "xxxx",
#' mode_of_transport = "0",
#' partner_2 = "World",
#' customs_code = "C00",
#' update = FALSE
#' ))
#'
#' @returns a httr2 request object
#' @inheritParams ct_get_data
ct_build_request <- function(params,
primary_token = NULL,
verbose = FALSE) {
primary_token = NULL,
verbose = FALSE) {
query_params <- params$query_params

extra_params <- params$extra_params |>
purrr::map(unlist) |>
purrr::pluck(1) |>
as.list()
query_params <- c(query_params, extra_params)
type <- params$url_params$type

freq <- params$url_params$freq
Expand All @@ -47,12 +56,12 @@ ct_build_request <- function(params,
httr2::req_headers(`Ocp-Apim-Subscription-Key` = primary_token) |>
httr2::req_url_query(!!!query_params)

if(stringr::str_length(res$url)>4095){
if (stringr::str_length(res$url) > 4095) {
rlang::abort("Your request exceeds 4KB or 4096 characters, which is the upper limit of the Comtrade API.") # nolint
}

if (verbose) {
cli::cli_inform(c("i" = paste0("URL that will be queried: ",res$url)))
cli::cli_inform(c("i" = paste0("URL that will be queried: ", res$url)))
}

return(res)
Expand Down
Loading
Loading