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

commodity_lookup() Returning Named Vector in Specific Situations #2

ChrisMuir opened this issue Jul 4, 2017 · 1 comment

Comments

@ChrisMuir
Copy link
Member

@ChrisMuir ChrisMuir commented Jul 4, 2017

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 added a commit that referenced this issue Jul 4, 2017
@ChrisMuir
Copy link
Member Author

@ChrisMuir ChrisMuir commented Jul 4, 2017

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"
@ChrisMuir ChrisMuir closed this Jul 4, 2017
@ChrisMuir ChrisMuir mentioned this issue Sep 9, 2017
11 of 14 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.