Giter VIP home page Giter VIP logo

worldbank's Introduction

worldbank

Lifecycle: experimental R-CMD-check

Overview

The goal of worldbank is to provide a simple interface to the World Bank API v2. The main difference to other packages is that it’s a modern implementation using the httr2 package without any other dependencies.

The worldbank package provides a set of functions to interact with various endpoints of the World Bank API. Each function is designed to retrieve specific types of data, making it easier to access and analyze World Bank datasets. Below is an overview of the available endpoints and their corresponding functions in the package:

  • Languages (wb_language): Retrieves a list of all languages supported by the World Bank API. Useful for obtaining language-specific data.
  • Lending Types (wb_lending_type): Fetches information about different lending types as recognized by the World Bank.
  • Income Levels (wb_income_level): Allows users to access data about various income levels defined by the World Bank.
  • Sources (wb_source): Provides details about the different data sources available within the World Bank’s datasets.
  • Topics (wb_topic): Lists all topics covered by the World Bank API, helping users to narrow down their data search to specific areas of interest.
  • Regions (wb_region): Offers information on different geographical regions as categorized by the World Bank.
  • Countries (wb_country): Enables access to detailed data about individual countries, including socio-economic and developmental indicators.
  • Country Indicators (wb_country_indicator): Specific to retrieving indicators for a particular country or countries, allowing for more targeted data analysis.
  • Indicators (wb_indicator): This endpoint gives users access to a wide array of indicators used by the World Bank in its data analysis and reports.

Installation

You can install the development version of worldbank from GitHub with:

# install.packages("pak")
pak::pak("m-muecke/worldbank")

Usage

worldbank functions are prefixed with wb_ and follow the naming convention of the World Bank API v2.

library(worldbank)

# filter by specific country
wb_country(c("US", "DE"))
#> # A tibble: 2 × 18
#>   country_id country_code country_name  region_id region_code region_value      
#>   <chr>      <chr>        <chr>         <chr>     <chr>       <chr>             
#> 1 DEU        DE           Germany       ECS       Z7          Europe & Central …
#> 2 USA        US           United States NAC       XU          North America     
#> # ℹ 12 more variables: admin_region_id <chr>, admin_region_code <chr>,
#> #   admin_region_value <chr>, income_level_id <chr>, income_level_code <chr>,
#> #   income_level_value <chr>, lending_type_id <chr>, lending_type_code <chr>,
#> #   lending_type_value <chr>, capital_city <chr>, longitude <dbl>,
#> #   latitude <dbl>

# or fetch all (default)
wb_country()
#> # A tibble: 296 × 18
#>   country_id country_code country_name        region_id region_code region_value
#>   <chr>      <chr>        <chr>               <chr>     <chr>       <chr>       
#> 1 ABW        AW           Aruba               LCN       ZJ          Latin Ameri…
#> 2 AFE        ZH           Africa Eastern and… NA        NA          Aggregates  
#> 3 AFG        AF           Afghanistan         SAS       8S          South Asia  
#> 4 AFR        A9           Africa              NA        NA          Aggregates  
#> 5 AFW        ZI           Africa Western and… NA        NA          Aggregates  
#> # ℹ 291 more rows
#> # ℹ 12 more variables: admin_region_id <chr>, admin_region_code <chr>,
#> #   admin_region_value <chr>, income_level_id <chr>, income_level_code <chr>,
#> #   income_level_value <chr>, lending_type_id <chr>, lending_type_code <chr>,
#> #   lending_type_value <chr>, capital_city <chr>, longitude <dbl>,
#> #   latitude <dbl>

# fetch indicator data for specific country
indicators <- wb_country_indicator("NY.GDP.MKTP.CD")
indicators
#> # A tibble: 13,198 × 10
#>    date indicator_id indicator_name country_id country_name country_code   value
#>   <int> <chr>        <chr>          <chr>      <chr>        <chr>          <dbl>
#> 1  2022 NY.GDP.MKTP… GDP (current … ZH         Africa East… AFE          1.19e12
#> 2  2021 NY.GDP.MKTP… GDP (current … ZH         Africa East… AFE          1.09e12
#> 3  2020 NY.GDP.MKTP… GDP (current … ZH         Africa East… AFE          9.29e11
#> 4  2019 NY.GDP.MKTP… GDP (current … ZH         Africa East… AFE          1.01e12
#> 5  2018 NY.GDP.MKTP… GDP (current … ZH         Africa East… AFE          1.01e12
#> # ℹ 13,193 more rows
#> # ℹ 3 more variables: unit <chr>, obs_status <chr>, decimal <int>

Related work

  • wbstats: An R package for searching and downloading data from the World Bank API
  • WDI: R package to download World Bank data

worldbank's People

Contributors

dependabot[bot] avatar m-muecke avatar pre-commit-ci[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

worldbank's Issues

Extend README.md example

Add common workflow, i.e. searching for indicator -> fetching indicator -> plotting indicator with ggplot2, just use US GDP or some indicator like that and overlay with another country or all countries

Release worldbank 0.1.0

First release:

Prepare for release:

  • git pull
  • urlchecker::url_check()
  • devtools::build_readme()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • git push
  • Draft blog post

Submit to CRAN:

  • usethis::use_version('minor')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • Add preemptive link to blog post in pkgdown news menu
  • usethis::use_github_release()
  • usethis::use_dev_version(push = TRUE)
  • usethis::use_news_md()
  • Finish blog post
  • Tweet

Support multiple indicators

The API can currently only handle multiple indicators if they're from the same data source.
The following could be done:

  • don't support multiple indicators (user calls the function twice)
  • only provide the source param in url when the indicators are length > 1 and just throw the endpoint error or check prior that all indicators are from the same source, which would require another call to indicator endpoint to get the id, which would be kinda pointless

Conversion to R types

  • id col should be numeric, haven't found a case where its not an integer id
  • empty strings should be NA
  • Y and N should be logical, for example in source endpoint for data_availability

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.