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

countryname() gives warning with numeric destination #309

Closed NilsEnevoldsen closed 2 years ago

NilsEnevoldsen commented 2 years ago

countryname (created as a result of #239) gives a warning if the destination is numeric (or more precisely "not character"). This causes a warning (not an error) in one of our tests: https://github.com/vincentarelbundock/countrycode/blob/4c45ec9f346692aaa7eaa0ca8d254b93ba3fa3a6/tests/testthat/test-countryname.R#L13

For example:

> countrycode::countryname('Japan','iso3c')
[1] "JPN"
> countrycode::countryname('Japan','iso3n')
Warning in countrycode_convert(sourcevar = sourcevar, origin = origin, destination = dest,  :
  The origin and destination codes are not of the same
                    class. Filling-in bad matches with NA instead.
[1] 392

This happens because countryname.R that passes along a parameter to countrycode_convert that doesn't make sense for a numeric destination context:

https://github.com/vincentarelbundock/countrycode/blob/4c45ec9f346692aaa7eaa0ca8d254b93ba3fa3a6/R/countryname.R#L50

On the other hand, the warning is intended for situations like this:

> countrycode::countrycode('JPN','iso3c','iso3n', nomatch = NULL)
Warning in countrycode_convert(sourcevar = sourcevar, origin = origin, destination = dest,  :
  The origin and destination codes are not of the same
                    class. Filling-in bad matches with NA instead.
[1] 392
vincentarelbundock commented 2 years ago

Thanks a lot for the diagnostic. I hope this is "fixed" by https://github.com/vincentarelbundock/countrycode/commit/6cd1d7877b6f6260f0e0f4de93c300c25c37fb13

Edit: fixed link to wrong commit

vincentarelbundock commented 2 years ago

closing now but feel free to re-open if it doesn't work on your end.