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

commodity_lookup() Returning Named Vector in Specific Situations #2

Closed
ChrisMuir opened this issue Jul 4, 2017 · 1 comment
Closed

Comments

@ChrisMuir
Copy link
Member

In function commodity_lookup(), if there is one (and only one) search result for each element of the input arg values, the return is a named vector, regardless of whether arg return_char is TRUE or FALSE. The intention is for the function to return an unnamed vector if return_char is TRUE, and a list if return_char is FALSE.

Here are two reproducible examples:

Ex. 1:

commoditydf <- comtradr::ct_commodities_table(type = "HS")
input_commod <- commoditydf$commodity[c(10, 20, 30, 40)]
commodity_lookup(input_commod, commoditydf, return_code = TRUE, return_char = TRUE)

returns

                                        010119 - Horses; live, other than pure-bred breeding animals 
                                                                                            "010119" 
                                                  010231 - Buffalo; live, pure-bred breeding animals 
                                                                                            "010231" 
0105 - Poultry; live, fowls of the species gallus domesticus, ducks, geese, turkeys and guinea fowls 
                                                                                              "0105" 
             010594 - Poultry; live, fowls of the species Gallus domesticus, weighing more than 185g 
                                                                                            "010594"

Ex. 2:

commoditydf <- comtradr::ct_commodities_table(type = "HS")
input_commod <- c("010119", "010231", "010594")
commodity_lookup(input_commod, commoditydf, return_code = FALSE, return_char = FALSE)

returns

                                                                                   010119 
                           "010119 - Horses; live, other than pure-bred breeding animals" 
                                                                                   010231 
                                     "010231 - Buffalo; live, pure-bred breeding animals" 
                                                                                   010594 
"010594 - Poultry; live, fowls of the species Gallus domesticus, weighing more than 185g"
@ChrisMuir
Copy link
Member Author

This issue has been fixed in commit #54.

Going back to the two example cases:

Ex 1:

commoditydf <- comtradr::ct_commodities_table(type = "HS")
input_commod <- commoditydf$commodity[c(10, 20, 30, 40)]
commodity_lookup(input_commod, commoditydf, return_code = TRUE, return_char = TRUE)

now returns

[1] "010119" "010231" "0105"   "010594"

Ex. 2:

commoditydf <- comtradr::ct_commodities_table(type = "HS")
input_commod <- c("010119", "010231", "010594")
commodity_lookup(input_commod, commoditydf, return_code = FALSE, return_char = FALSE)

now returns

$`010119`
[1] "010119 - Horses; live, other than pure-bred breeding animals"

$`010231`
[1] "010231 - Buffalo; live, pure-bred breeding animals"

$`010594`
[1] "010594 - Poultry; live, fowls of the species Gallus domesticus, weighing more than 185g"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant