Learn R Programming

rdbnomics (version 0.4.7)

rdb_by_api_link: Download DBnomics data using API link.

Description

rdb_by_api_link downloads data series from DBnomics.

Usage

rdb_by_api_link(api_link,
  use_readLines = getOption("rdbnomics.use_readLines"),
  curl_config = getOption("rdbnomics.curl_config"))

Arguments

api_link

Character string. DBnomics API link of the search.

use_readLines

Logical (default FALSE). If TRUE, then the data are requested and read with the base function readLines i.e. through the default R internet connection. This can be used to get round the error Could not resolve host: api.db.nomics.world.

curl_config

Curl_handle or list (default NULL). If not NULL, it is used to configure a proxy connection. This configuration is passed to the function curl_fetch_memory of the package curl. If it is a curl_handle object then it is considered to be the argument handle of curl_fetch_memory. In the case of a list, the names of the object are the arguments names of curl_fetch_memory (except url of course). It means that curl_config = h is equivalent to curl_config = list(handle = h). For curl_fetch_memory arguments see curl_fetch. For available curl options see curl_options, names(curl_options()) and libcurl.

Value

A data.frame or a data.table.

Details

This function gives you access to hundreds of millions data series from DBnomics API (documentation about the API can be found here). The API link is given on the DBnomics website.

See Also

rdb

Examples

Run this code
# NOT RUN {
# Fetch two series from different datasets of different providers :
df1 <- rdb_by_api_link(
  paste0(
    'https://api.db.nomics.world/v22/',
    'series?observations=1&series_ids=AMECO/ZUTN/EA19.1.0.0.0.ZUTN,IMF/CPI/A.AT.PCPIT_IX'
  )
)

# Fetch one series from the dataset 'Doing Business' of WB provider :
df2 <- rdb_by_api_link(
  paste0(
    'https://api.db.nomics.world/v22/series/WB/DB?dimensions=%7B%22',
    'indicator%22%3A%5B%22IC.REG.PROC.FE.NO%22%5D%7D&q=Doing%20Business',
    '&observations=1&format=json&align_periods=1&offset=0&facets=0'
  )
)


## Use a specific proxy to fetch the data
# Fetch one series from the dataset 'Doing Business' of WB provider :
h <- curl::new_handle(
  proxy = "<proxy>",
  proxyport = <port>,
  proxyusername = "<username>",
  proxypassword = "<password>"
)
options(rdbnomics.curl_config = h)
df2 <- rdb_by_api_link(
  paste0(
    'https://api.db.nomics.world/v22/series/WB/DB?dimensions=%7B%22',
    'indicator%22%3A%5B%22IC.REG.PROC.FE.NO%22%5D%7D&q=Doing%20Business',
    '&observations=1&format=json&align_periods=1&offset=0&facets=0'
  )
)
# or to use once
df2 <- rdb_by_api_link(
  paste0(
    'https://api.db.nomics.world/v22/series/WB/DB?dimensions=%7B%22',
    'indicator%22%3A%5B%22IC.REG.PROC.FE.NO%22%5D%7D&q=Doing%20Business',
    '&observations=1&format=json&align_periods=1&offset=0&facets=0'
  ),
  curl_config = h
)


## Use R default connection to avoid a proxy failure (in some cases)
# Fetch one series from the dataset 'Doing Business' of WB provider :
options(rdbnomics.use_readLines = TRUE)
df2 <- rdb_by_api_link(
  paste0(
    'https://api.db.nomics.world/v22/series/WB/DB?dimensions=%7B%22',
    'indicator%22%3A%5B%22IC.REG.PROC.FE.NO%22%5D%7D&q=Doing%20Business',
    '&observations=1&format=json&align_periods=1&offset=0&facets=0'
  )
)
# or to use once
df2 <- rdb_by_api_link(
  paste0(
    'https://api.db.nomics.world/v22/series/WB/DB?dimensions=%7B%22',
    'indicator%22%3A%5B%22IC.REG.PROC.FE.NO%22%5D%7D&q=Doing%20Business',
    '&observations=1&format=json&align_periods=1&offset=0&facets=0'
  ),
  use_readLines = TRUE
)
# }

Run the code above in your browser using DataLab