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 |
from |
Code format from which to convert. Defaults to |
short |
Whether to use short alternative name when available. Can be
length 1 or the same length as |
variant |
Whether to use variant alternative name when available. Can
be length 1 or the same length as |
factor |
If |
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
-
the UN Statistics Division(UNSD), which maintains standardized names in English, Chinese, Russian, French, Spanish, and Arabic, here named as
"en_un"
etc. -
the ISO,
"en_iso"
and"fr_iso"
, and -
-
"en_cia"
, which include many longer official forms and shorter practical forms, -
"en_cia_local"
, which includes transliterations, and -
"en_cia_abbreviation"
, which includes commonly-used abbreviations.
-
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