Search code examples
rcountry-codes

countrycode package not recognizing "SOM" as ISO3 character code for Somalia - r


I am getting a strange result trying to convert from ISO3 character code to World Bank Code. Notably Somalia is not recognized in ISO3

Somalia ISO3 character code is "SOM": https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3

Example:

library(countrycode)
place <- data.frame("iso3c" = "SOM")

place
  iso3c
1   SOM

place$wb <- countrycode(sourcevar = place$iso3c, origin = "iso3c", destination = "wb")
Warning message:
In countrycode(sourcevar = place$iso3c, origin = "iso3c", destination = "wb") :
  Some values were not matched unambiguously: SOM

place
  iso3c   wb
1   SOM <NA>

Since World Bank code for Somalia is also SOM, I can get around this by setting nomatch = NULL.

place$wb <- countrycode(sourcevar = place$iso3c, origin = "iso3c", destination = "wb", nomatch = NULL)
place
  iso3c  wb
1   SOM SOM

But this behavior still seems wrong. Am I missing something or is this a bug?


Solution

  • It's a bug. I submitted an issue here.

    I would argue the most preferable current workaround (until it's fixed) would be...

    place$wb <- countrycode(sourcevar = place$iso3c, origin = "iso3c", destination = "wb", custom_match = c("SOM" = "SOM"))
    

    which makes it extremely clear what is happening, and easy to remove if/when the bug is fixed.