Skip to content

Commit

Permalink
changed flow_direction parameter to case-insensitive to avoid confusi…
Browse files Browse the repository at this point in the history
…on and make the update non-breaking for old code snippets (except for 'all')
  • Loading branch information
datapumpernickel committed Dec 17, 2023
1 parent b662fa4 commit c3af057
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 14 deletions.
5 changes: 3 additions & 2 deletions R/ct_check_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,14 @@ check_flowCode <- function(flow_direction, update, verbose) {
flow_direction <- as.character(flow_direction)

# remove any white space from cmd codes provided
flow_direction <- stringr::str_squish(flow_direction)
flow_direction <- stringr::str_squish(flow_direction) |> tolower()

# get the list of valid parameters from inst/extdata
valid_codes <-
ct_get_ref_table(dataset_id = 'flow_direction',
update = update,
verbose = verbose)
verbose = verbose) |>
poorman::mutate(text = tolower(text))

rlang::arg_match(flow_direction, values = valid_codes$text, multiple = T)

Expand Down
5 changes: 3 additions & 2 deletions R/ct_get_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
#' See `comtradr::ct_get_ref_table('HS')` for possible values.
#' Default: 'TOTAL' (sum of all commodities).
#' @param flow_direction The direction of trade flows or `everything`.
#' Possible values can be found in `ct_get_ref_table('flow_direction')`.
#' Default: c('Import','Export','Re-export','Re-import').
#' Possible values can be found in `ct_get_ref_table('flow_direction')`. These
#' are implemented case-insensitive, 'import' and 'Import' are equivalent.
#' Default: c('import','export','re-export','re-import').
#' @param reporter Reporter ISO3 code(s) or `NULL`.
#' See `comtradr::country_codes` or `comtradr::ct_get_ref_table('reporter')`
#' for possible values. Default: 'all'.
Expand Down
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ testthat
twi
useability
ℹ️
EB
5 changes: 3 additions & 2 deletions man/ct_check_params.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/ct_get_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions vignettes/comtradr.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ example_1 <- ct_get_data(
commodity_code = 'TOTAL',
start_date = 2018,
end_date = 2023,
flow_direction = 'Import'
flow_direction = 'import'
)
```
API calls return a tidy data frame.
Expand All @@ -100,15 +100,15 @@ By default, the return data is in yearly amounts. We can pass `"monthly"` to arg
# Get all monthly data for a single year (API max of 12 months per call).
q <- ct_search(reporters = "USA",
partners = c("Germany", "France", "Japan", "Mexico"),
flow_direction = "Import",
flow_direction = "import",
start_date = 2012,
end_date = 2012,
freq = "monthly")
# Get monthly data for a specific span of months (API max of twelve months per call).
q <- ct_search(reporters = "USA",
partners = c("Germany", "France", "Japan", "Mexico"),
flow_direction = "Import",
flow_direction = "import",
start_date = "2012-03",
end_date = "2012-07",
freq = "monthly")
Expand All @@ -133,7 +133,7 @@ q <- ct_get_data(
commodity_code = tomato_codes,
start_date = "2012",
end_date = "2013",
flow_direction = 'Import'
flow_direction = 'import'
)
```
On the other hand, if we wanted to exclude juices and sauces from our search, we can pass a vector of the relevant codes to the API call.
Expand All @@ -144,7 +144,7 @@ q <- ct_get_data(
commodity_code = c("0702", "070200", "2002", "200210", "200290"),
start_date = "2012",
end_date = "2013",
flow_direction = 'Import'
flow_direction = 'import'
)
```
Expand Down Expand Up @@ -258,7 +258,7 @@ example_2 <- ct_get_data(
commodity_code = 'TOTAL',
start_date = 2012,
end_date = 2023,
flow_direction = 'Export'
flow_direction = 'export'
)
```

Expand Down

0 comments on commit c3af057

Please sign in to comment.