Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

r.loaders

Description

r.loaders is an R package with utility functions for retrieving data from the ECB Data Portal and connecting to SQL Server databases.

The main functions are:

  • get_sdw() – retrieves data from the ECB Data Portal

  • get_conn() – creates an ODBC connection to a SQL Server database

    • The resulting connection can be used with DBI, dbplyr, or other database tools
  • close_conn() – closes an ODBC connection

  • clean_sdw_cache() – clears cached ECB data

Installation

# install.packages("remotes")
remotes::install_github("ajnikitins/r.loaders")

ECB data

get_sdw() retrieves data from the ECB Data Portal using SDMX dataset and key identifiers.

For example:

library(r.loaders)

data <- get_sdw(
  "BSI",
  key = "M.U2.N.A.T00.A.1.Z5.0000.Z01.E"
)

The SDMX key can also be supplied as a vector:

data <- get_sdw(
  "BSI",
  key = c("M", "U2", "N", "A", "T00", "A", "1", "Z5", "0000", "Z01", "E")
)

Additional arguments can be used to restrict the requested time period or number of observations.

Caching ECB queries

Queries made with get_sdw() are cached by default. This is particularly useful for large datasets and automated projects that are updated regularly.

When a cached query is repeated, r.loaders checks whether the data published by the ECB have changed since the previous request. If no new data are available, the cached data are used instead of downloading and processing the dataset again.

By default, the cache is stored in the temporary directory of the R session. A persistent cache directory can instead be specified for an individual query:

data <- get_sdw(
  "BSI",
  key = "M.U2.N.A.T00.A.1.Z5.0000.Z01.E",
  cache_dir = "path/to/cache"
)

or for the entire R session:

options(loaders.sdw_cache_dir = "path/to/cache")

The cache can be deleted using:

clean_sdw_cache()

See the get_sdw() documentation for additional caching options.

SQL connections

get_conn() provides a simple wrapper for creating an ODBC connection to SQL Server:

con <- get_conn(
  server = "SERVER",
  database = "DATABASE"
)

The connection can then be used with packages such as DBI or dbplyr and closed using:

close_conn(con)

Acknowledgements

  • Artūrs Jānis Ņikitins – package author
  • Colleagues at Latvijas Banka
  • Eric Persson – ecb package

About

R utilities for retrieving and caching ECB Data Portal data and connecting to SQL Server

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages