MyNixOS website logo
Description

'Global Data Lab' R API.

Retrieve datasets from the 'Global Data Lab' website <https://globaldatalab.org> directly into R data frames. Functions are provided to reference available options (indicators, levels, countries, regions) as well.

gdldata

CRAN Status

Retrieve datasets from the Global Data Lab (GDL) website directly into R data frames. Functions are provided to reference available options (indicators, regions, countries) as well.

Prerequisites

To work with the gdldata package, an API access token is required. Such a token may be created for free on the Global Data Lab website. Simply log in, go to 'My GDL', and go to 'API Access'.

Note that, by default, GDL only allows one active token per user. However, for academic purposes, this limit may be increased, e.g. to facilitate classroom settings.

Installation

# Install released version from CRAN
install.packages("gdldata")
# Install development version from GitHub
devtools::install_github("GlobalDataLab/R-data-api")

Usage

To get started, include the gdldata library:

library(gdldata)

Then create a GDL session object using your personal API access token, e.g.:

sess <- gdl_session("SUBSTITUTE-WITH-YOUR-ACCESS-TOKEN")

This session object can be used to build your next API request, and facilitates partial request reuse. For example, we can use it to retrieve the IWI indicator for India:

sess <- set_indicator(sess, 'iwi')
sess <- set_country(sess, 'IND')
iwi_india <- gdl_request(sess)

We can reuse the same session object to retrieve more data. For example, we reuse it to retrieve several SHDI indicators for Belgium, Luxembourg, and The Netherlands:

sess <- set_dataset(sess, 'shdi')
sess <- set_countries(sess, c('BEL', 'LUX', 'NLD'))
sess <- set_indicators(sess, c('healthindex', 'edindex', 'incindex'))
shdi_benelux <- gdl_request(sess)

Using pipes instead

To reduce verbosity, popular pipe operators may be used as well. You can either use the built-in pipe operator |> (R >= 4.1) or use the %>% operator from magrittr as a substitute. Consider the following example:

library(magrittr)

sess <- sess %>%
    set_dataset('shdi') %>%
    set_countries(c('BEL', 'LUX', 'NLD')) %>%
    set_indicators(c('healthindex', 'edindex', 'incindex')) %>%
shdi_benelux <- gdl_request(sess)

Note that we could prepend gdl_session() and append gdl_request() to the pipe chain as well. However, to facilitate reuse of the session object, we recommend against this.

Additional reference functions

The GDL database may be explored fully without having to fall back to browsing the website. To this end, we provide the following reference functions:

gdl_indicators(session)    # retrieves a list of indicators
gdl_levels(session)        # retrieves a list of aggregation levels
gdl_countries(session)     # retrieves a list of available countries
gdl_regions(session, iso3) # retrieves a list of regions in a particular country

Contributing

We welcome bug reports and feature requests in our issue tracker on GitHub.

Metadata

Version

0.1

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows