get_data | R Documentation |
This is the main function of the package to retrieve data from the database. It constructs an SQL query which is sent to the database and returns the data as a data.table
in R.
get_data( dsid = NULL, series = NULL, from = NULL, to = NULL, labels = TRUE, wide = TRUE, expand.date = FALSE, ordered = TRUE, return.query = FALSE, ... )
dsid |
character. (Optional) id's of datasets matching the 'DSID' column of the 'DATASET' table (retrieved using |
series |
character. (Optional) codes of series matching the 'Series' column of the 'Series' table (retrieved using |
from |
set the start time of the data retrieved by either supplying a start date, a date-string of the form |
to |
same as |
labels |
logical. |
wide |
logical. |
expand.date |
logical. |
ordered |
logical. |
return.query |
logical. |
... |
further arguments passed to |
If labels = FALSE
, the 'SERIES' table is not joined to the 'DATA' table, and ordered = TRUE
will order datasets and series retrieved in alphabetic order.
If labels = TRUE
data is ordered by series and date within each dataset, preserving the order of columns in the dataset. If multiple datasets are received they are ordered alphabetically according to the 'DSID' column.
It is possible query multiple series from multiple datasets e.g. get_data(c("DSID1", "DSID2"), c("SERFROM1", "SERFROM2"))
etc., but care needs to be taken that the series queried do not occur in both datasets (see .IDvars
, and check using series(c("DSID1", "DSID2"))
).
Series from datasets at different frequencies can be queried, but, if wide = TRUE
, this will result in missing values for all but the first observations per period in the lower frequency series.
A data.table
with the result of the query.
long2wide
, expand_date
, ugatsdb
# Return monthly macroeconomic indicators from the year 2000 onwards get_data("BOU_MMI", from = 2000, wide = FALSE) # Return wide format with date expanded get_data("BOU_MMI", from = 2000, expand.date = TRUE) # Same thing in multiple steps (with additional customization options): library(magrittr) # Pipe %>% operators get_data("BOU_MMI", from = 2000, wide = FALSE) %>% long2wide %>% expand_date # Getting a single series get_data("BOU_MMI", "M2", 2000) # Getting High-Frequency activity indicators from BoU and Revenue & Expense from MoFPED get_data(c("BOU_MMI", "MOF_TOT", "WB_WDI"), c("CIEA", "BTI", "REV_GRA", "EXP_LEN")) # Getting daily interest rates and plotting library(xts) # Time series class get_data("BOU_I", from = 2018, wide = FALSE) %>% long2wide(names_from = "Label") %>% as.xts %>% plot(legend.loc = "topleft")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.