https://github.com/ropenspain/tidybde
R package that helps to retrieve data from Banco de España
https://github.com/ropenspain/tidybde
api bde cran ggplot2 macroeconomics r r-package ropenspain rstats series-data spain
Last synced: 2 months ago
JSON representation
R package that helps to retrieve data from Banco de España
- Host: GitHub
- URL: https://github.com/ropenspain/tidybde
- Owner: rOpenSpain
- License: gpl-3.0
- Created: 2021-04-01T00:15:16.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2025-03-18T20:48:48.000Z (about 1 year ago)
- Last Synced: 2025-04-11T13:14:25.338Z (about 1 year ago)
- Topics: api, bde, cran, ggplot2, macroeconomics, r, r-package, ropenspain, rstats, series-data, spain
- Language: R
- Homepage: https://ropenspain.github.io/tidyBdE/
- Size: 84.1 MB
- Stars: 11
- Watchers: 1
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Citation: CITATION.cff
- Codemeta: codemeta.json
Awesome Lists containing this project
README
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
tidy = "styler",
comment = "#>",
fig.path = "man/figures/README-",
warning = FALSE,
message = FALSE,
dev = "ragg_png",
dpi = 300,
out.width = "100%"
)
```
# tidyBdE 
[](https://ropenspain.es/)
[](https://CRAN.R-project.org/package=tidyBdE)
[](https://cran.r-project.org/web/checks/check_results_tidyBdE.html)
[](https://cran.r-project.org/package=tidyBdE)
[](https://cran.r-project.org/web/checks/check_results_tidyBdE.html)
[](https://ropenspain.r-universe.dev/tidyBdE)
[](https://github.com/rOpenSpain/tidyBdE/actions/workflows/check-full.yaml)
[](https://github.com/rOpenSpain/tidyBdE/actions/workflows/rhub.yaml)
[](https://app.codecov.io/gh/ropenspain/tidyBdE)
[](https://www.codefactor.io/repository/github/ropenspain/tidybde)
[](https://doi.org/10.32614/CRAN.package.tidyBdE)
[](https://www.repostatus.org/#active)
**tidyBdE** is an API package that retrieves data from [Banco de
España](https://www.bde.es/webbe/en/estadisticas/recursos/descargas-completas.html).
The data is returned as a [tibble](https://tibble.tidyverse.org/), and the
package automatically detects the format of each time-series (dates, characters,
and numbers).
## Installation
Install **tidyBdE** from [**CRAN**](https://CRAN.R-project.org/package=tidyBdE):
```{r, eval = FALSE}
install.packages("tidyBdE")
```
You can install the development version of **tidyBdE** with:
```{r, eval = FALSE}
remotes::install_github("ropenspain/tidyBdE")
```
Alternatively, you can install the development version of **tidyBdE** using the
[r-universe](https://ropenspain.r-universe.dev/tidyBdE):
```{r, eval = FALSE}
# Install tidyBdE in R:
install.packages("tidyBdE", repos = c(
"https://ropenspain.r-universe.dev",
"https://cloud.r-project.org"
))
```
## Examples
Banco de España (**BdE**) provides several time-series, either produced by the
institution itself or compiled from other sources, such as
[Eurostat](https://ec.europa.eu/eurostat) or [INE](https://www.ine.es/).
The basic entry point for searching time-series is the catalogs (*indexes*) of
information. You can search any series by name:
```{r search, message=FALSE}
library(tidyBdE)
# Load tidyverse for better handling
library(ggplot2)
library(dplyr)
library(tidyr)
# Search GBP on "TC" (exchange rate) catalog
xr_gbp <- bde_catalog_search("GBP", catalog = "TC")
xr_gbp |>
select(Numero_secuencial, Descripcion_de_la_serie) |>
# To table on document
knitr::kable()
```
**Note that BdE files are currently only provided in Spanish.** The institution
is working on the English version. For now, search terms must be provided in
Spanish to retrieve results.
After we have found our series, we can load the series for the GBP/EUR exchange
rate using the sequential number reference (`Numero_Secuencial`) as:
```{r find}
seq_number <- xr_gbp |>
# First record
slice(1) |>
# Get id
select(Numero_secuencial) |>
# Convert to num
as.double()
# Extract series
time_series <- bde_series_load(seq_number, series_label = "EUR_GBP_XR") |>
filter(Date >= "2010-01-01" & Date <= "2020-12-31") |>
drop_na()
```
### Plots
The package also provides a custom **ggplot2** theme based on BdE publications:
```{r chart, fig.asp=0.7, fig.alt="EUR/GBP Exchange Rate (2010-2020)"}
ggplot(time_series, aes(x = Date, y = EUR_GBP_XR)) +
geom_line(colour = bde_tidy_palettes(n = 1)) +
geom_smooth(method = "gam", colour = bde_tidy_palettes(n = 2)[2]) +
labs(
title = "EUR/GBP Exchange Rate (2010-2020)",
subtitle = "%",
caption = "Source: BdE"
) +
geom_vline(
xintercept = as.Date("2016-06-23"),
linetype = "dotted"
) +
geom_label(aes(
x = as.Date("2016-06-23"),
y = .95,
label = "Brexit"
)) +
coord_cartesian(ylim = c(0.7, 1)) +
theme_tidybde()
```
The package also provides several "shortcut" functions for a selection of
relevant macroeconomic series, so there is no need to search for them in
advance:
```{r macroseries, fig.asp=0.7, fig.alt="Spanish Economic Indicators (2010-2019)"}
# Data in "long" format
plotseries <- bde_ind_gdp_var("GDP YoY", out_format = "long") |>
bind_rows(
bde_ind_unemployment_rate("Unemployment Rate", out_format = "long")
) |>
drop_na() |>
filter(Date >= "2010-01-01" & Date <= "2019-12-31")
ggplot(plotseries, aes(x = Date, y = serie_value)) +
geom_line(aes(color = serie_name), linewidth = 1) +
labs(
title = "Spanish Economic Indicators (2010-2019)",
subtitle = "%",
caption = "Source: BdE"
) +
theme_tidybde() +
scale_color_bde_d(palette = "bde_vivid_pal") # Custom palette on the package
```
### Palettes
Two custom palettes, based on those used by BdE in some publications, are
available.
These palettes can be applied to `ggplot2` plots using custom utilities included
in the package (see `help("scale_color_bde_d", package = "tidyBdE")`).
### A note on caching
You can use **tidyBdE** to create your own local repository in a given local
directory by passing the following option:
``` r
options(bde_cache_dir = "./path/to/location")
```
When this option is set, **tidyBdE** looks for the cached file in the
`bde_cache_dir` directory and loads it, speeding up the process.
It is possible to update the data (i.e. after every monthly or quarterly data
release) with the following commands:
```{r, eval = FALSE}
bde_catalog_update()
# On most of the functions using the option update_cache = TRUE
bde_series_load("SOME ID", update_cache = TRUE)
```
## Disclaimer
This package is in no way sponsored, endorsed, or administered by Banco de
España.
## Citation
```{r echo=FALSE, results='asis'}
print(citation("tidyBdE"), style = "html")
```
A BibTeX entry for LaTeX users is
```{r echo=FALSE, comment=""}
toBibtex(citation("tidyBdE"))
```