This package provides a single function that takes an .iqy file generated by the Statistical Database of the Central Bank of Chile, and returns a data frame with the results of the query.
The main benefit of working with .iqy files is that you can easily
update your data by using the query parameters, so that you do not need
to access the BCCh site every time you want to obtain the latest data
available. Also, it is important to note that, while these files were
designed to work with Microsoft Excel, you don’t actually need to have
this program installed on your computer to be able to use .iqy files
with BCChqRy
.
if (!require(remotes)) {
install.packages('remotes')
}
remotes::install_github('miguelbiron/BCChqRy')
In this brief example, I assume you have downloaded and placed in your
working directory the UF_IVP_DIARIO.iqy
file associated with the query
“Precios” > “UF - IVP - UTM” > “UF-IVP diario” in the BCCh database.
For this file, we know that the query parameters are the initial and
final year for the data requested. In fact, this is the case for every
.iqy file from the BCCh that I have tested. Therefore, we pass these to
the q_values
argument.
library(BCChqRy)
suppressPackageStartupMessages(library(dplyr))
get_bcch_data("UF_IVP_DIARIO.iqy", q_values = c(2018, 2018)) %>%
head() %>%
knitr::kable()
| FECHA | Unidad de fomento (UF) | Indice de valor promedio (IVP) | | :--------- | ---------------------: | -----------------------------: | | 2018-01-01 | 26799.01 | 27918.44 | | 2018-01-02 | 26799.87 | 27919.31 | | 2018-01-03 | 26800.73 | 27920.18 | | 2018-01-04 | 26801.60 | 27921.05 | | 2018-01-05 | 26802.46 | 27921.92 | | 2018-01-06 | 26803.33 | 27922.79 |
As you navigate the database, you will
eventually arrive at a dataset that you’d like to download, including an
appropriate frequency (“frecuencia”) and calculation (“calculo”). Now,
simply click the
button located in the upper-right corner above the data table. This will
download the .iqy file associated with the data you requested, which you
can then use in R with BCChqRy
.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.