The analysis counterpart to world_data(): no polygons, one tidy row per
country (iso3c, iso2c, country, classifications and the requested
indicators). This is what you actually join() / mutate() / summarise()
/ rank() on; attach geometry only at draw time with attach_geometry().
Usage
country_data(
year,
indicator = NULL,
latest = FALSE,
panel = FALSE,
classify = c("income", "continent", "region"),
cache = TRUE,
language = "en",
parallel = TRUE,
vintage = NULL
)Arguments
- year
A single year or a range (with
panel = TRUE).- indicator
A named character vector of WDI codes (or
NULLfor none).- latest
For a single year:
TRUEtakes each indicator's most recent non-NAvalue per country,"common"the most recent year in which every indicator is present. Both add an<indicator>_yearcolumn per indicator; see the section below.- panel
Return a panel keyed on
iso3c+year(implied whenyearspans multiple years).- classify
Which classifications to add.
- cache
Whether to use the WDI cache.
- language
WDI language code.
- parallel
Whether to fetch indicators in parallel. Ignored when the cache is memory-only; see
world_data().- vintage
The release of the World Development Indicators to read; see
world_data().
Value
A tibble, one row per country (or per country-year for a panel).
iso3c is the stable key; country is a label and its spelling depends on
where the row came from. A successful fetch carries the World Bank's names
("Korea, Rep.", "Congo, Dem. Rep."), while the country spine used when the
fetch returns nothing carries the countrycode names ("South Korea",
"Congo - Kinshasa") – as do convert_country(), standardize_country()
and the rest of the package. Match on iso3c, and relabel with
convert_country(iso3c, to = "country") if you need one consistent set.
The most recent value, and which year it is from
With latest = TRUE each indicator takes its own most recent value, so one
row can hold GDP from 2023 beside population from 2021. That is often what
is wanted – the freshest number for each – but dividing one by the other
mixes years, so every indicator carries an <indicator>_year column, and
per_capita(), deflate() and to_ppp() warn (class
countryatlas_mixed_years) when the two columns they combine come from
different years. latest = "common" instead takes, per country, the most
recent year in which every requested indicator is present, so the row is
internally consistent; a country with no such year gets NA throughout.
Examples
# \donttest{
country_data(2020, c(co2 = "EN.GHG.CO2.MT.CE.AR5"))
#> # A tibble: 216 × 7
#> iso3c iso2c country continent region income co2
#> <chr> <chr> <chr> <chr> <chr> <fct> <dbl>
#> 1 AFG AF Afghanistan Asia Middle East, North… Low i… 12.1
#> 2 ALB AL Albania Europe Europe & Central A… Upper… 4.57
#> 3 DZA DZ Algeria Africa Middle East, North… Upper… 172.
#> 4 ASM AS American Samoa Oceania East Asia & Pacific High … 0.0001
#> 5 AND AD Andorra Europe Europe & Central A… High … NA
#> 6 AGO AO Angola Africa Sub-Saharan Africa Lower… 20.5
#> 7 ATG AG Antigua and Barbuda Americas Latin America & Ca… High … 0.326
#> 8 ARG AR Argentina Americas Latin America & Ca… Upper… 168.
#> 9 ARM AM Armenia Asia Europe & Central A… Upper… 6.91
#> 10 ABW AW Aruba Americas Latin America & Ca… High … 0.489
#> # ℹ 206 more rows
# }
