Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
DBnomics : the world’s economic database
Explore all the economic data from different providers (national and international statistical institutes, central banks, etc.), for free, following the link db.nomics.world.
You can also retrieve all the economic data through the rdbnomics
package here. This blog post describes the different ways to do so.
Fetch time series by ids
First, let’s assume that we know which series we want to download. A series identifier (ids
) is defined by three values, formatted like this: provider_code
/dataset_code
/series_code
.
Fetch one series from dataset ‘Unemployment rate’ (ZUTN) of AMECO provider
if (!"pacman" %in% installed.packages()[,"Package"]) install.packages("pacman", repos='http://cran.r-project.org') pacman::p_load(tidyverse,rdbnomics,magrittr,lubridate,knitr,zoo) df <- rdb(ids = 'AMECO/ZUTN/EA19.1.0.0.0.ZUTN') %>% filter(!is.na(value))
In such data.frame (data.table or tibble), you will always find at least ten columns:
provider_code
dataset_code
dataset_name
series_code
series_name
original_period
(character string)period
(date of the first day oforiginal_period
)original_value
(character string)value
@frequency
(harmonized frequency generated by DBnomics)
The other columns depend on the provider and on the dataset. They always come in pairs (for the code and the name). In the data.frame df
, you have:
unit
(code) andUnit
(name)geo
(code) andCountry
(name)freq
(code) andFrequency
(name)
## # A tibble: 24 x 17 ## provider_code dataset_code dataset_name series_code series_name ## <chr> <chr> <chr> <chr> <chr> ## 1 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## 2 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## 3 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## 4 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## 5 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## 6 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## 7 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## 8 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## 9 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## 10 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## # … with 14 more rows, and 12 more variables: original_period <chr>, ## # period <date>, original_value <chr>, value <dbl>, `@frequency` <chr>, ## # unit <chr>, Unit <chr>, geo <chr>, Country <chr>, freq <chr>, ## # Frequency <chr>, indexed_at <dttm> ggplot(df, aes(x = period, y = value, color = series_name)) + geom_line(size = 1.2) + geom_point(size = 2) + dbnomics()
In the event that you only use the argument ids
, you can drop it and run:
df <- rdb('AMECO/ZUTN/EA19.1.0.0.0.ZUTN')
Fetch two series from dataset ‘Unemployment rate’ (ZUTN) of AMECO provider
df <- rdb(ids = c('AMECO/ZUTN/EA19.1.0.0.0.ZUTN', 'AMECO/ZUTN/DNK.1.0.0.0.ZUTN')) %>% filter(!is.na(value)) ## # A tibble: 86 x 17 ## provider_code dataset_code dataset_name series_code series_name ## <chr> <chr> <chr> <chr> <chr> ## 1 AMECO ZUTN Unemploymen… DNK.1.0.0.… Annually –… ## 2 AMECO ZUTN Unemploymen… DNK.1.0.0.… Annually –… ## 3 AMECO ZUTN Unemploymen… DNK.1.0.0.… Annually –… ## 4 AMECO ZUTN Unemploymen… DNK.1.0.0.… Annually –… ## 5 AMECO ZUTN Unemploymen… DNK.1.0.0.… Annually –… ## 6 AMECO ZUTN Unemploymen… DNK.1.0.0.… Annually –… ## 7 AMECO ZUTN Unemploymen… DNK.1.0.0.… Annually –… ## 8 AMECO ZUTN Unemploymen… DNK.1.0.0.… Annually –… ## 9 AMECO ZUTN Unemploymen… DNK.1.0.0.… Annually –… ## 10 AMECO ZUTN Unemploymen… DNK.1.0.0.… Annually –… ## # … with 76 more rows, and 12 more variables: original_period <chr>, ## # period <date>, original_value <chr>, value <dbl>, `@frequency` <chr>, ## # unit <chr>, Unit <chr>, geo <chr>, Country <chr>, freq <chr>, ## # Frequency <chr>, indexed_at <dttm> ggplot(df, aes(x = period, y = value, color = series_name)) + geom_line(size = 1.2) + geom_point(size = 2) + dbnomics()
Fetch two series from different datasets of different providers
df <- rdb(ids = c('AMECO/ZUTN/EA19.1.0.0.0.ZUTN', 'Eurostat/une_rt_q/Q.SA.TOTAL.PC_ACT.T.EA19')) %>% filter(!is.na(value)) ## # A tibble: 110 x 27 ## provider_code dataset_code dataset_name series_code series_name ## <chr> <chr> <chr> <chr> <chr> ## 1 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## 2 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## 3 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## 4 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## 5 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## 6 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## 7 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## 8 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## 9 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## 10 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## # … with 100 more rows, and 22 more variables: original_period <chr>, ## # period <date>, original_value <chr>, value <dbl>, `@frequency` <chr>, ## # unit <chr>, Unit <chr>, geo <chr>, Country <chr>, freq <chr>, ## # Frequency <chr>, age <chr>, `Age class` <chr>, FREQ <chr>, `Geopolitical ## # entity (reporting)` <chr>, indexed_at <dttm>, ## # observations_attributes <chr>, s_adj <chr>, `Seasonal adjustment` <chr>, ## # sex <chr>, Sex <chr>, `Unit of measure` <chr> ggplot(df, aes(x = period, y = value, color = series_name)) + geom_line(size = 1.2) + geom_point(size = 2) + dbnomics() + theme(legend.text = element_text(size=7))
Fetch time series by mask
The code mask notation is a very concise way to select one or many time series at once. It is compatible only with some providers : BIS, ECB, Eurostat, FED, ILO, IMF, INSEE, OECD, WTO.
Fetch one series from dataset ‘Balance of Payments’ (BOP) of IMF
df <- rdb('IMF', 'BOP', mask = 'A.FR.BCA_BP6_EUR') %>% filter(!is.na(value)) ## # A tibble: 20 x 18 ## provider_code dataset_code dataset_name series_code series_name ## <chr> <chr> <chr> <chr> <chr> ## 1 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## 2 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## 3 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## 4 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## 5 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## 6 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## 7 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## 8 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## 9 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## 10 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## 11 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## 12 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## 13 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## 14 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## 15 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## 16 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## 17 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## 18 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## 19 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## 20 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## # … with 13 more variables: original_period <chr>, period <date>, ## # original_value <chr>, value <dbl>, `@frequency` <chr>, FREQ <chr>, ## # Frequency <chr>, indexed_at <dttm>, Indicator <chr>, INDICATOR <chr>, ## # observations_attributes <chr>, REF_AREA <chr>, `Reference Area` <chr> ggplot(df, aes(x = period, y = value, color = series_name)) + geom_line(size = 1.2) + geom_point(size = 2) + dbnomics()
In the event that you only use the arguments provider_code
, dataset_code
and mask
, you can drop the name mask
and run:
df <- rdb('IMF', 'BOP', 'A.FR.BCA_BP6_EUR')
Fetch two series from dataset ‘Balance of Payments’ (BOP) of IMF
You just have to add a +
between two different values of a dimension.
df <- rdb('IMF', 'BOP', mask = 'A.FR+ES.BCA_BP6_EUR') %>% filter(!is.na(value)) ## # A tibble: 40 x 18 ## provider_code dataset_code dataset_name series_code series_name ## <chr> <chr> <chr> <chr> <chr> ## 1 IMF BOP Balance of … A.ES.BCA_B… Annual – S… ## 2 IMF BOP Balance of … A.ES.BCA_B… Annual – S… ## 3 IMF BOP Balance of … A.ES.BCA_B… Annual – S… ## 4 IMF BOP Balance of … A.ES.BCA_B… Annual – S… ## 5 IMF BOP Balance of … A.ES.BCA_B… Annual – S… ## 6 IMF BOP Balance of … A.ES.BCA_B… Annual – S… ## 7 IMF BOP Balance of … A.ES.BCA_B… Annual – S… ## 8 IMF BOP Balance of … A.ES.BCA_B… Annual – S… ## 9 IMF BOP Balance of … A.ES.BCA_B… Annual – S… ## 10 IMF BOP Balance of … A.ES.BCA_B… Annual – S… ## # … with 30 more rows, and 13 more variables: original_period <chr>, ## # period <date>, original_value <chr>, value <dbl>, `@frequency` <chr>, ## # FREQ <chr>, Frequency <chr>, indexed_at <dttm>, Indicator <chr>, ## # INDICATOR <chr>, observations_attributes <chr>, REF_AREA <chr>, `Reference ## # Area` <chr> ggplot(df, aes(x = period, y = value, color = series_name)) + geom_line(size = 1.2) + geom_point(size = 2) + dbnomics()
Fetch all series along one dimension from dataset ‘Balance of Payments’ (BOP) of IMF
df <- rdb('IMF', 'BOP', mask = 'A..BCA_BP6_EUR') %>% filter(!is.na(value)) %>% arrange(desc(period), REF_AREA) %>% head(100) ## # A tibble: 100 x 18 ## provider_code dataset_code dataset_name series_code series_name ## <chr> <chr> <chr> <chr> <chr> ## 1 IMF BOP Balance of … A.AL.BCA_B… Annual – A… ## 2 IMF BOP Balance of … A.AT.BCA_B… Annual – A… ## 3 IMF BOP Balance of … A.BE.BCA_B… Annual – B… ## 4 IMF BOP Balance of … A.CY.BCA_B… Annual – C… ## 5 IMF BOP Balance of … A.DE.BCA_B… Annual – G… ## 6 IMF BOP Balance of … A.EE.BCA_B… Annual – E… ## 7 IMF BOP Balance of … A.ES.BCA_B… Annual – S… ## 8 IMF BOP Balance of … A.FI.BCA_B… Annual – F… ## 9 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## 10 IMF BOP Balance of … A.GR.BCA_B… Annual – G… ## # … with 90 more rows, and 13 more variables: original_period <chr>, ## # period <date>, original_value <chr>, value <dbl>, `@frequency` <chr>, ## # FREQ <chr>, Frequency <chr>, indexed_at <dttm>, Indicator <chr>, ## # INDICATOR <chr>, observations_attributes <chr>, REF_AREA <chr>, `Reference ## # Area` <chr>
Fetch series along multiple dimensions from dataset ‘Balance of Payments’ (BOP) of IMF
df <- rdb('IMF', 'BOP', mask = 'A.FR.BCA_BP6_EUR+IA_BP6_EUR') %>% filter(!is.na(value)) %>% group_by(INDICATOR) %>% top_n(n = 50, wt = period) ## # A tibble: 40 x 18 ## # Groups: INDICATOR [2] ## provider_code dataset_code dataset_name series_code series_name ## <chr> <chr> <chr> <chr> <chr> ## 1 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## 2 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## 3 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## 4 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## 5 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## 6 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## 7 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## 8 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## 9 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## 10 IMF BOP Balance of … A.FR.BCA_B… Annual – F… ## # … with 30 more rows, and 13 more variables: original_period <chr>, ## # period <date>, original_value <chr>, value <dbl>, `@frequency` <chr>, ## # FREQ <chr>, Frequency <chr>, indexed_at <dttm>, Indicator <chr>, ## # INDICATOR <chr>, observations_attributes <chr>, REF_AREA <chr>, `Reference ## # Area` <chr>
Fetch time series by dimensions
Searching by dimensions
is a less concise way to select time series than using the code mask
, but it works with all the different providers. You have a “Description of series code” at the bottom of each dataset page on the DBnomics website.
Fetch one value of one dimension from dataset ‘Unemployment rate’ (ZUTN) of AMECO provider
df <- rdb('AMECO', 'ZUTN', dimensions = list(geo = "ea19")) %>% filter(!is.na(value)) # or # df <- rdb('AMECO', 'ZUTN', dimensions = '{"geo": ["ea19"]}') %>% # filter(!is.na(value)) ## # A tibble: 24 x 17 ## provider_code dataset_code dataset_name series_code series_name ## <chr> <chr> <chr> <chr> <chr> ## 1 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## 2 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## 3 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## 4 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## 5 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## 6 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## 7 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## 8 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## 9 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## 10 AMECO ZUTN Unemploymen… EA19.1.0.0… Annually –… ## # … with 14 more rows, and 12 more variables: original_period <chr>, ## # period <date>, original_value <chr>, value <dbl>, `@frequency` <chr>, ## # unit <chr>, Unit <chr>, geo <chr>, Country <chr>, freq <chr>, ## # Frequency <chr>, indexed_at <dttm> ggplot(df, aes(x = period, y = value, color = series_name)) + geom_line(size = 1.2) + geom_point(size = 2) + dbnomics()
Fetch two values of one dimension from dataset ‘Unemployment rate’ (ZUTN) of AMECO provider
df <- rdb('AMECO', 'ZUTN', dimensions = list(geo = c("ea19", "dnk"))) %>% filter(!is.na(value)) # or # df <- rdb('AMECO', 'ZUTN', dimensions = '{"geo": ["ea19", "dnk"]}') %>% # filter(!is.na(value)) ## # A tibble: 86 x 17 ## provider_code dataset_code dataset_name series_code series_name ## <chr> <chr> <chr> <chr> <chr> ## 1 AMECO ZUTN Unemploymen… DNK.1.0.0.… Annually –… ## 2 AMECO ZUTN Unemploymen… DNK.1.0.0.… Annually –… ## 3 AMECO ZUTN Unemploymen… DNK.1.0.0.… Annually –… ## 4 AMECO ZUTN Unemploymen… DNK.1.0.0.… Annually –… ## 5 AMECO ZUTN Unemploymen… DNK.1.0.0.… Annually –… ## 6 AMECO ZUTN Unemploymen… DNK.1.0.0.… Annually –… ## 7 AMECO ZUTN Unemploymen… DNK.1.0.0.… Annually –… ## 8 AMECO ZUTN Unemploymen… DNK.1.0.0.… Annually –… ## 9 AMECO ZUTN Unemploymen… DNK.1.0.0.… Annually –… ## 10 AMECO ZUTN Unemploymen… DNK.1.0.0.… Annually –… ## # … with 76 more rows, and 12 more variables: original_period <chr>, ## # period <date>, original_value <chr>, value <dbl>, `@frequency` <chr>, ## # unit <chr>, Unit <chr>, geo <chr>, Country <chr>, freq <chr>, ## # Frequency <chr>, indexed_at <dttm> ggplot(df, aes(x = period, y = value, color = series_name)) + geom_line(size = 1.2) + geom_point(size = 2) + dbnomics()
Fetch several values of several dimensions from dataset ‘Doing business’ (DB) of World Bank
df <- rdb('WB', 'DB', dimensions = list(country = c("DZ", "PE"), indicator = c("ENF.CONT.COEN.COST.ZS", "IC.REG.COST.PC.FE.ZS"))) %>% filter(!is.na(value)) # or # df <- rdb('WB', 'DB', dimensions = '{"country": ["DZ", "PE"], "indicator": ["ENF.CONT.COEN.COST.ZS", "IC.REG.COST.PC.FE.ZS"]}') %>% # filter(!is.na(value)) ## # A tibble: 68 x 14 ## provider_code dataset_code dataset_name series_code series_name ## <chr> <chr> <chr> <chr> <chr> ## 1 WB DB Doing Busin… IC.REG.COS… Cost of bu… ## 2 WB DB Doing Busin… IC.REG.COS… Cost of bu… ## 3 WB DB Doing Busin… IC.REG.COS… Cost of bu… ## 4 WB DB Doing Busin… IC.REG.COS… Cost of bu… ## 5 WB DB Doing Busin… IC.REG.COS… Cost of bu… ## 6 WB DB Doing Busin… IC.REG.COS… Cost of bu… ## 7 WB DB Doing Busin… IC.REG.COS… Cost of bu… ## 8 WB DB Doing Busin… IC.REG.COS… Cost of bu… ## 9 WB DB Doing Busin… IC.REG.COS… Cost of bu… ## 10 WB DB Doing Busin… IC.REG.COS… Cost of bu… ## # … with 58 more rows, and 9 more variables: original_period <chr>, ## # period <date>, original_value <chr>, value <dbl>, `@frequency` <chr>, ## # country <chr>, indexed_at <dttm>, indicator <chr>, ## # observations_attributes <chr> ggplot(df, aes(x = period, y = value, color = series_name)) + geom_line(size = 1.2) + geom_point(size = 2) + dbnomics()
Fetch time series found on the web site
When you don’t know the codes of the dimensions, provider, dataset or series, you can:
-
go to the page of a dataset on DBnomics website, for example Doing Business,
-
select some dimensions by using the input widgets of the left column,
-
click on “Copy API link” in the menu of the “Download” button,
-
use the
rdb_by_api_link
function such as below.
df <- rdb_by_api_link("https://api.db.nomics.world/v22/series/WB/DB?dimensions=%7B%22country%22%3A%5B%22FR%22%2C%22IT%22%2C%22ES%22%5D%7D&q=IC.REG.PROC.FE.NO&observations=1&format=json&align_periods=1&offset=0&facets=0") %>% filter(!is.na(value)) ## Warning: 'rdb_by_api_link(api_link = ...)' is deprecated. ## Use 'rdb(api_link = ...)' instead. ## See help("Deprecated") ## # A tibble: 51 x 14 ## provider_code dataset_code dataset_name series_code series_name ## <chr> <chr> <chr> <chr> <chr> ## 1 WB DB Doing Busin… IC.REG.PRO… Starting a… ## 2 WB DB Doing Busin… IC.REG.PRO… Starting a… ## 3 WB DB Doing Busin… IC.REG.PRO… Starting a… ## 4 WB DB Doing Busin… IC.REG.PRO… Starting a… ## 5 WB DB Doing Busin… IC.REG.PRO… Starting a… ## 6 WB DB Doing Busin… IC.REG.PRO… Starting a… ## 7 WB DB Doing Busin… IC.REG.PRO… Starting a… ## 8 WB DB Doing Busin… IC.REG.PRO… Starting a… ## 9 WB DB Doing Busin… IC.REG.PRO… Starting a… ## 10 WB DB Doing Busin… IC.REG.PRO… Starting a… ## # … with 41 more rows, and 9 more variables: original_period <chr>, ## # period <date>, original_value <chr>, value <dbl>, `@frequency` <chr>, ## # country <chr>, indexed_at <dttm>, indicator <chr>, ## # observations_attributes <chr> ggplot(df, aes(x = period, y = value, color = series_name)) + geom_step(size = 1.2) + geom_point(size = 2) + dbnomics()
Fetch time series from the cart
On the cart page of the DBnomics website, click on “Copy API link” and copy-paste it as an argument of the rdb_by_api_link
function. Please note that when you update your cart, you have to copy this link again, because the link itself contains the ids of the series in the cart.
df <- rdb_by_api_link("https://api.db.nomics.world/v22/series?observations=1&series_ids=BOE/6008/RPMTDDC,BOE/6231/RPMTBVE") %>% filter(!is.na(value)) ## Warning: 'rdb_by_api_link(api_link = ...)' is deprecated. ## Use 'rdb(api_link = ...)' instead. ## See help("Deprecated") ## # A tibble: 250 x 27 ## provider_code dataset_code dataset_name series_code series_name ## <chr> <chr> <chr> <chr> <chr> ## 1 BOE 6008 Industrial … RPMTDDC "Monthly a… ## 2 BOE 6231 Industrial … RPMTBVE "Monthly a… ## 3 BOE 6008 Industrial … RPMTDDC "Monthly a… ## 4 BOE 6231 Industrial … RPMTBVE "Monthly a… ## 5 BOE 6008 Industrial … RPMTDDC "Monthly a… ## 6 BOE 6231 Industrial … RPMTBVE "Monthly a… ## 7 BOE 6008 Industrial … RPMTDDC "Monthly a… ## 8 BOE 6231 Industrial … RPMTBVE "Monthly a… ## 9 BOE 6008 Industrial … RPMTDDC "Monthly a… ## 10 BOE 6231 Industrial … RPMTBVE "Monthly a… ## # … with 240 more rows, and 22 more variables: original_period <chr>, ## # period <date>, original_value <chr>, value <dbl>, `@frequency` <chr>, ## # freq <chr>, Freq <chr>, indexed_at <dttm>, `Instrument Currency` <chr>, ## # INSTRUMENT_CURRENCY <chr>, Instruments <chr>, INSTRUMENTS <chr>, `Of ## # Sector` <chr>, OF_SECTOR <chr>, `Output In` <chr>, OUTPUT_IN <chr>, ## # `Seasonal Adjustment` <chr>, SEASONAL_ADJUSTMENT <chr>, Sector <chr>, ## # SECTOR <chr>, Type <chr>, TYPE <chr> ggplot(df, aes(x = period, y = value, color = series_name)) + geom_line(size = 1.2) + geom_point(size = 2) + dbnomics()
Proxy configuration or connection error Could not resolve host
When using the functions rdb
or rdb_...
, you may come across the following error:
Error in open.connection(con, "rb") : Could not resolve host: api.db.nomics.world
To get round this situation, you have two options:
-
configure curl to use a specific and authorized proxy.
-
use the default R internet connection i.e. the Internet Explorer proxy defined in internet2.dll.
Configure curl to use a specific and authorized proxy
In rdbnomics, by default the function curl_fetch_memory
(of the package curl) is used to fetch the data. If a specific proxy must be used, it is possible to define it permanently with the package option rdbnomics.curl_config
or on the fly through the argument curl_config
. Because the object is a named list, its elements are passed to the connection (the curl_handle
object created internally with new_handle()
) with handle_setopt()
before using curl_fetch_memory
.
To see the available parameters, run names(curl_options())
in R or visit the website https://curl.haxx.se/libcurl/c/curl_easy_setopt.html. Once they are chosen, you define the curl object as follows:
h <- list( proxy = "<proxy>", proxyport = <port>, proxyusername = "<username>", proxypassword = "<password>" )
Set the connection up for a session
The curl connection can be set up for a session by modifying the following package option:
options(rdbnomics.curl_config = h)
When fetching the data, the following command is executed:
hndl <- curl::new_handle() curl::handle_setopt(hndl, .list = getOption("rdbnomics.curl_config")) curl::curl_fetch_memory(url = <...>, handle = hndl)
After configuration, just use the standard functions of rdbnomics e.g.:
df1 <- rdb(ids = 'AMECO/ZUTN/EA19.1.0.0.0.ZUTN')
This option of the package can be disabled with:
options(rdbnomics.curl = NULL)
Use the connection only for a function call
If a complete configuration is not needed but just an “on the fly” execution, then use the argument curl_config
of the functions rdb
and rdb_...
:
df1 <- rdb(ids = 'AMECO/ZUTN/EA19.1.0.0.0.ZUTN', curl_config = h)
Use the default R internet connection
To retrieve the data with the default R internet connection, rdbnomics will use the base function readLines
.
Set the connection up for a session
To activate this feature for a session, you need to enable an option of the package :
options(rdbnomics.use_readLines = TRUE)
And then use the standard function as follows :
df1 <- rdb(ids = 'AMECO/ZUTN/EA19.1.0.0.0.ZUTN')
This configuration can be disabled with :
options(rdbnomics.use_readLines = FALSE)
Use the connection only for a function call
If you just want to do it once, you may use the argument use_readLines
of the functions rdb
and rdb_...
:
df1 <- rdb(ids = 'AMECO/ZUTN/EA19.1.0.0.0.ZUTN', use_readLines = TRUE)
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.