fetch_indicator() plus country_join() in one step: pull an indicator from
any registered source and attach it to a frame you already have, matched on
the ISO spine (and on year too, when both sides are panels).
Arguments
- data
A frame with
iso3c(or a country columnjoin_world()would recognise).- source, indicator, countries, years, ...
Passed to
fetch_indicator().countriesdefaults to the codes already indata, so you never have to restate them. How much that saves depends on the source – see below.
How much countries actually saves
countries bounds the result, not necessarily the download. Only some
providers accept a country filter in the request:
| Source | countries reaches the provider? |
comtrade | yes – sent as reporter |
wdi | partly – the year range is sent, countries are filtered here |
owid, eurostat, oecd | no – the full dataset is downloaded, then filtered |
So add_indicator(one_row, "owid", "life-expectancy") still transfers every
country and year that dataset holds in order to keep a single value. When
that matters, narrow with years (which the wdi and comtrade adapters do
push down), or fetch once into a variable and reuse it rather than calling
this per subset. The on-disk cache means a repeated wdi fetch is free;
the other sources are memoised for the session only.
Examples
if (FALSE) { # \dontrun{
world_snapshot$countries |>
add_indicator("wdi", c(unemployment = "SL.UEM.TOTL.ZS"), years = 2020)
} # }
