rdbnomics (version 0.5.0)

rdb: Download DBnomics data.

Description

rdb downloads data series from DBnomics using shortcuts like ids, dimensions or mask.

Usage

rdb(provider_code = NULL, dataset_code = NULL, ids = NULL,
  dimensions = NULL, mask = NULL,
  filters = getOption("rdbnomics.filters"),
  verbose = getOption("rdbnomics.verbose_warning"), ...)

Arguments

provider_code

Character string (default NULL). DBnomics code of the provider.

dataset_code

Character string (default NULL). DBnomics code of the dataset.

ids

Character string (default NULL). DBnomics code of one or several series.

dimensions

List or character string (single quoted) (default NULL). DBnomics code of one or several dimensions in the specified provider and dataset. If it is a named list, then the function toJSON (from the package jsonlite) is applied to generate the json object.

mask

Character string (default NULL). DBnomics code of one or several masks in the specified provider and dataset.

filters

List (default NULL). This argument must be a named list for one filter because the function toJSON of the package jsonlite is used before sending the request to the server. For multiple filters, you have to provide a list of valid filters (see examples). A valid filter is a named list with an element code which is a character string, and an element parameters which is a named list with elements frequency and method or a NULL.

verbose

Logical (default FALSE). Show warnings of the function.

...

Arguments to be passed to rdb_by_api_link. These arguments concern connection configuration. See rdb_by_api_link for details.

Value

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 code of each series is given on the DBnomics website. In the event that only the argument ids is provided (and those in the ellipsis ...), the argument name can be dropped. The character string vector is directly passed to ids. In the same way, if only provider_code, dataset_code and mask are provided then the arguments names can be dropped. The last character string is automatically passed to mask.

See Also

rdb_by_api_link

Examples

Run this code
# NOT RUN {
## By ids
# Fetch one series from dataset 'Unemployment rate' (ZUTN) of AMECO provider :
df1 <- rdb(ids = 'AMECO/ZUTN/EA19.1.0.0.0.ZUTN')
# or when no argument names are given (provider_code -> ids)
df1 <- rdb('AMECO/ZUTN/EA19.1.0.0.0.ZUTN')

# Fetch two series from dataset 'Unemployment rate' (ZUTN) of AMECO provider :
df2 <- rdb(ids = c('AMECO/ZUTN/EA19.1.0.0.0.ZUTN', 'AMECO/ZUTN/DNK.1.0.0.0.ZUTN'))

# Fetch two series from different datasets of different providers :
df3 <- rdb(ids = c('AMECO/ZUTN/EA19.1.0.0.0.ZUTN', 'IMF/CPI/A.AT.PCPIT_IX'))


## By dimensions
# Fetch one value of one dimension from dataset 'Unemployment rate' (ZUTN) of AMECO provider :
df1 <- rdb('AMECO', 'ZUTN', dimensions = list(geo = "ea12"))
# or
df1 <- rdb('AMECO', 'ZUTN', dimensions = '{"geo": ["ea12"]}')

# Fetch two values of one dimension from dataset 'Unemployment rate' (ZUTN) of AMECO provider :
df2 <- rdb('AMECO', 'ZUTN', dimensions = list(geo = c("ea12", "dnk")))
# or
df2 <- rdb('AMECO', 'ZUTN', dimensions = '{"geo": ["ea12", "dnk"]}')

# Fetch several values of several dimensions from dataset 'Doing business' (DB) of World Bank :
dim <- list(
  country = c("DZ", "PE"),
  indicator = c("ENF.CONT.COEN.COST.ZS", "IC.REG.COST.PC.FE.ZS")
)
df3 <- rdb('WB', 'DB', dimensions = dim)
# or
dim <- paste0(
  '{"country": ["DZ", "PE"],',
  '"indicator": ["ENF.CONT.COEN.COST.ZS", "IC.REG.COST.PC.FE.ZS"]}'
)
df3 <- rdb('WB', 'DB', dimensions = dim)


## By mask
# Fetch one series from dataset 'Consumer Price Index' (CPI) of IMF :
df1 <- rdb('IMF', 'CPI', mask = 'M.DE.PCPIEC_WT')
# or when no argument names are given except provider_code and dataset_code (ids -> mask)
df1 <- rdb('IMF', 'CPI', 'M.DE.PCPIEC_WT')

# Fetch two series from dataset 'Consumer Price Index' (CPI) of IMF :
df2 <- rdb('IMF', 'CPI', mask = 'M.DE+FR.PCPIEC_WT')

# Fetch all series along one dimension from dataset 'Consumer Price Index' (CPI) of IMF :
df3 <- rdb('IMF', 'CPI', mask = 'M..PCPIEC_WT')

# Fetch series along multiple dimensions from dataset 'Consumer Price Index' (CPI) of IMF :
df4 <- rdb('IMF', 'CPI', mask = 'M..PCPIEC_IX+PCPIA_IX')


## Use a specific proxy to fetch the data
# Fetch one series from dataset 'Unemployment rate' (ZUTN) of AMECO provider :
h <- list(
  proxy = "<proxy>",
  proxyport = <port>,
  proxyusername = "<username>",
  proxypassword = "<password>"
)
options(rdbnomics.curl_config = h)
df1 <- rdb(ids = 'AMECO/ZUTN/EA19.1.0.0.0.ZUTN')
# or to use once
options(rdbnomics.curl_config = NULL)
df1 <- rdb(ids = 'AMECO/ZUTN/EA19.1.0.0.0.ZUTN', curl_config = h)


## Use R default connection to avoid a proxy failure (in some cases)
# Fetch one series from dataset 'Unemployment rate' (ZUTN) of AMECO provider :
options(rdbnomics.use_readLines = TRUE)
df1 <- rdb(ids = 'AMECO/ZUTN/EA19.1.0.0.0.ZUTN')
# or to use once
df1 <- rdb(ids = 'AMECO/ZUTN/EA19.1.0.0.0.ZUTN', use_readLines = TRUE)


## Apply filter(s) to the series
# One filter
df1 <- rdb(
  ids = c("IMF/WEO/ABW.BCA", "IMF/WEO/ABW.BCA_NGDPD"),
  filters = list(
    code = "interpolate",
    parameters = list(frequency = "daily", method = "spline")
  )
)

# Two filters
df1 <- rdb(
  ids = c("IMF/WEO/ABW.BCA", "IMF/WEO/ABW.BCA_NGDPD"),
  filters = list(
    list(
      code = "interpolate",
      parameters = list(frequency = "quarterly", method = "spline")
    ),
    list(
      code = "aggregate",
      parameters = list(frequency = "annual", method = "average")
    )
  )
)
# }

Run the code above in your browser using DataCamp Workspace