vincentarelbundock / countrycode

R package: Convert country names and country codes. Assigns region descriptors.
https://vincentarelbundock.github.io/countrycode
GNU General Public License v3.0
342 stars 84 forks source link

Odd behavior when using `custom_dict` with `codelist` #358

Closed mcooper closed 2 months ago

mcooper commented 3 months ago

I would expect both of these to give the same result, but they dont:

countrycode("Myanmar", "country.name", "iso3c")

countrycode("Myanmar", "country.name", "iso3c", custom_dict = countrycode::codelist)

I am trying to make a tweak to codelist for one specific country-code (I want to assign Kosovo an ISO-3 code), and I would like to make countrycode() otherwise behave the same. I tried doing that by editing codelist, but using codelist as the custom_dict seems to have other effects.

cjyetman commented 3 months ago

I would suggest using the custom_match argument...

library(countrycode)
countries <- c("Myanmar", "Kosovo", "Republic of Kosovo")
countrycode(countries, "country.name", "iso3c", custom_match = c(Kosovo = "XKK", `Republic of Kosovo` = "XKK"))
#> [1] "MMR" "XKK" "XKK"