as_country_name {passport}R Documentation

Convert standardized country codes to country names

Description

as_country_name converts a vector of standardized country codes to country names.

Usage

as_country_name(
  x,
  to = "en",
  from = "iso2c",
  short = TRUE,
  variant = FALSE,
  factor = is.factor(x)
)

Arguments

x

A character, factor, or numeric vector of country codes or names

to

Language code of country names desired. Defaults to "en"; see codes for more options.

from

Code format from which to convert. Defaults to "iso2c"; see codes for more options.

short

Whether to use short alternative name when available. Can be length 1 or the same length as x.

variant

Whether to use variant alternative name when available. Can be length 1 or the same length as x.

factor

If TRUE, returns factor instead of character vector. If not supplied, defaults to is.factor(x)

Details

as_country_name takes a character, factor, or numeric vector of country codes (or names in another standardized format) and converts them to country names in the specified format. If you are trying to standardize an existing set of names, see parse_country().

The default "en" is from Unicode Common Locale Data Repository (CLDR), which aspires to use the most customary name e.g. "Switzerland" instead of official ones, which are frequently awkward for common usage, e.g. "Swiss Confederation". CLDR also supplies names in a huge variety of languages, allowing for easy translation. Short and variant alternates are available for some countries; if not, the function will fall back to the standard form. See LICENSE file for terms of use.

Other name sets are available from

See codes for all options, or run DT::datatable(codes) for a searchable widget.

Value

A character or factor vector of country names. Warns if new NA values are added.

See Also

For converting standardized names to codes, use as_country_code(). For standardizing names to codes, use parse_country().

Examples

# Usable names for tough-to-standardize places
as_country_name(c("US", "TW", "MM", "XK", "KR"))

# If passed a factor, will return a releveled one
as_country_name(factor(c("US", "NF", "CD", "SJ")), short = FALSE, variant = TRUE)

# Speaks a lot of languages, knows a lot of codes
as_country_name(c("SAH", "PCN", "OMA", "JPN"), from = "fifa", to = "cy")    # to Welsh


[Package passport version 0.3.0 Index]