Selects, renames, and type-casts the most useful columns from an
SDG observation table returned by sdg_data(), producing a compact
tibble in the unified DSIR cleaned-indicator schema — the same
schema produced by gho_clean(), so the two outputs can be combined
directly with bind_indicators().
Arguments
- df
A data frame returned by
sdg_data().
Value
A tibble with 15 columns: source (always
"sdg"), id, indicator, location, iso3, location_name,
year, value, value_num, low, high, series, dim1
(NA), dim2 (NA), dim3 (NA). Sorted by location then
year. Empty input returns an empty tibble with the same columns
and types.
Details
The mapping (SDG source → unified column) is:
indicator(list-column, flattened) →id(e.g."3.4.1")seriesDescription→indicator(human-readable label;NAif the API response does not include it)geoAreaCode→location(UN M49 numeric, as character); alsoiso3viam49_to_iso3()for WHO Member States — region / world aggregates and non-Member areas getiso3 = NAlocation_nameis resolved by looking upiso3againstwho_countries(so a WHO Member State has the samelocation_namehere and ingho_clean()output), with a fallback to the SDG API's rawgeoAreaNamefor non-Member-State rows (e.g. regional / world aggregates)timePeriodStart→year(integer)value→value(character; raw) andvalue_num(numeric;NAfor non-numeric entries like"<0.1"or aggregate notes)lowerBound,upperBound→low,high(numeric)series→series
Three columns are always present but never populated for SDG
output: dim1, dim2, dim3 (GHO-only concepts).
Examples
# \donttest{
sdg_data("3.2.1", area = "156", year_from = 2015) |>
sdg_clean()
#> Fetching:
#> <https://unstats.un.org/sdgs/UNSDGAPIV5/v1/sdg/Indicator/Data?indicator=3.2.1&pageSize=1000&areaCode=156&page=1>
#> Waiting 2s for retry backoff ■■■■■■■■■■■■■■■
#> Waiting 2s for retry backoff ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
#> Waiting 4s for retry backoff ■■■■■■■■
#> Waiting 4s for retry backoff ■■■■■■■■■■■■■■■■■■
#> Waiting 4s for retry backoff ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
#> Warning: SDG request failed.
#> ℹ URL:
#> <https://unstats.un.org/sdgs/UNSDGAPIV5/v1/sdg/Indicator/Data?indicator=3.2.1&pageSize=1000&areaCode=156&page=1>
#> ✖ Failed to perform HTTP request. Caused by error in
#> `curl::curl_fetch_memory()`: ! Timeout was reached [unstats.un.org]:
#> Operation timed out after 30000 milliseconds with 0 bytes received
#> # A tibble: 0 × 15
#> # ℹ 15 variables: source <chr>, id <chr>, indicator <chr>, location <chr>,
#> # iso3 <chr>, location_name <chr>, year <int>, value <chr>, value_num <dbl>,
#> # low <dbl>, high <dbl>, series <chr>, dim1 <chr>, dim2 <chr>, dim3 <chr>
# }