gta_clean_country_names: Convert country names to GTA nomenclature

View source: R/clean country names.R

gta_clean_country_namesR Documentation

Convert country names to GTA nomenclature

Description

gta_clean_country_names() takes a vector of country names as an input and converts them to the country names used in the GTA database.

Usage

gta_clean_country_names(
    country,
    conversionTable = FALSE, 
    customConversion = NULL
)

Arguments

country

a vector of country names

conversionTable

set to TRUE if the function should return a conversion table which shows how each unique value in 'country' is converted by the function

customConversion

If you wish to overwrite the default function behavior you can add a named vector to the function which contains as names the name of the the country name to be converted and as value the name function should convert to. Eg: Your data contains South - and North Korea which you do not wnat to convert according to the GTA nomenclature: –> c("South Korea" = "Korea (S)", "North Korea" = "Korea, (N)")

Details

If a country cannot or cannot uniquely be matched to one country in the gta nomenclature, NA is returned. If you want a table with unique country names from the input vector, the name they were converted to and information on whether the function changed the name, set conversionTable to true. This will output a tibble with these three columns.

References

The function uses gtalibrary::country_regex which contains a regex for each country which inputs are matched against.

Examples

a_mess <- tibble::tible(
     country = c(
         "Korea, the one in the north",
         "Korea, this time in the south",
         "Burma", 
         "Germany (EU Country)", 
         "Bosnia",
          "USA"
    )

# a_mess %>% 
     mutate(clean_names = gta_clean_country_names(country))

# if you wish to convert the value "Korea, this time in the south" to "South Korea" and leave "USA" unchanged, 
supply a named vector to customConversion.
# function value: 
custom <- ("Korea, this time in the south" = "South Korea", "USA" = "USA")
a_mess %>% 
     mutate(clean_names = gta_clean_country_names(country, customConversion = custom))

global-trade-alert/gtalibrary documentation built on April 26, 2024, 12:38 p.m.