Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wb_country only returns single region, admin region, income level and lending type #24

Closed
christophscheuch opened this issue Sep 27, 2024 · 2 comments

Comments

@christophscheuch
Copy link

A country might belong to several of the categories in the title, hence I decided to provide nested tibbles for them in my implementation: https://github.com/tidy-intelligence/r-wbwdi/blob/4673f7e4697f23829e9f2288681737d500e889b4/R/list_supported_countries.R#L64.

For instance,

library(wbwdi)
countries |> filter(id == "USA") |>  unnest(income_levels)

returns

# A tibble: 3 × 10
  id    iso2_code name          capital_city    longitude latitude regions          admin_regions    income_level lending_types
  <chr> <chr>     <chr>         <chr>           <chr>     <chr>    <list>           <list>           <chr>        <list>       
1 USA   US        United States Washington D.C. -77.032   38.8895  <tibble [3 × 1]> <tibble [3 × 1]> HIC          <tibble>     
2 USA   US        United States Washington D.C. -77.032   38.8895  <tibble [3 × 1]> <tibble [3 × 1]> XD           <tibble>     
3 USA   US        United States Washington D.C. -77.032   38.8895  <tibble [3 × 1]> <tibble [3 × 1]> High income  <tibble>   

Might also be interesting for your package to feature these nested data.

@m-muecke
Copy link
Owner

m-muecke commented Sep 27, 2024

Makes sense, but I'm always getting one row back per country for the country endpoint.

library(httr2)
body <- request("https://api.worldbank.org/v2") |>
  req_url_path_append("en", "country", "USA") |>
  req_url_query(format = "json") |>
  req_perform() |>
  resp_body_json()
body[[2L]]
#> [[1]]
#> [[1]]$id
#> [1] "USA"
#> 
#> [[1]]$iso2Code
#> [1] "US"
#> 
#> [[1]]$name
#> [1] "United States"
#> 
#> [[1]]$region
#> [[1]]$region$id
#> [1] "NAC"
#> 
#> [[1]]$region$iso2code
#> [1] "XU"
#> 
#> [[1]]$region$value
#> [1] "North America"
#> 
#> 
#> [[1]]$adminregion
#> [[1]]$adminregion$id
#> [1] ""
#> 
#> [[1]]$adminregion$iso2code
#> [1] ""
#> 
#> [[1]]$adminregion$value
#> [1] ""
#> 
#> 
#> [[1]]$incomeLevel
#> [[1]]$incomeLevel$id
#> [1] "HIC"
#> 
#> [[1]]$incomeLevel$iso2code
#> [1] "XD"
#> 
#> [[1]]$incomeLevel$value
#> [1] "High income"
#> 
#> 
#> [[1]]$lendingType
#> [[1]]$lendingType$id
#> [1] "LNX"
#> 
#> [[1]]$lendingType$iso2code
#> [1] "XX"
#> 
#> [[1]]$lendingType$value
#> [1] "Not classified"
#> 
#> 
#> [[1]]$capitalCity
#> [1] "Washington D.C."
#> 
#> [[1]]$longitude
#> [1] "-77.032"
#> 
#> [[1]]$latitude
#> [1] "38.8895"

Created on 2024-09-27 with reprex v2.1.1

@christophscheuch
Copy link
Author

Ups, sorry, mistake on my end. I parse the nested data incorrectly and interpreted them as multiple entries 🤦

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants