Title: | Download and Tidy Data from the Reserve Bank of Australia |
Version: | 0.1.11 |
Description: | Download up-to-date data from the Reserve Bank of Australia in a tidy data frame. Package includes functions to download current and historical statistical tables (https://www.rba.gov.au/statistics/tables/) and forecasts (https://www.rba.gov.au/publications/smp/forecasts-archive.html). Data includes a broad range of Australian macroeconomic and financial time series. |
License: | MIT + file LICENSE |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2 |
URL: | https://mattcowgill.github.io/readrba/index.html |
BugReports: | https://github.com/MattCowgill/readrba/issues |
Suggests: | covr, testthat, knitr, rmarkdown, markdown, ggplot2 |
Imports: | readxl (≥ 1.3.0), tidyr (≥ 1.0.0), dplyr (≥ 1.0.0), purrr, rlang, xml2, rvest (≥ 0.3.6), stringr, httr, lubridate |
Depends: | R (≥ 3.6.0) |
VignetteBuilder: | knitr |
NeedsCompilation: | no |
Packaged: | 2024-09-27 09:32:49 UTC; mcowgill |
Author: | Matt Cowgill |
Maintainer: | Matt Cowgill <mattcowgill@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2024-09-27 13:50:02 UTC |
readrba: Download and Tidy Data from the Reserve Bank of Australia
Description
Download up-to-date data from the Reserve Bank of Australia in a tidy data frame. Package includes functions to download current and historical statistical tables (https://www.rba.gov.au/statistics/tables/) and forecasts (https://www.rba.gov.au/publications/smp/forecasts-archive.html). Data includes a broad range of Australian macroeconomic and financial time series.
Author(s)
Maintainer: Matt Cowgill mattcowgill@gmail.com (ORCID)
Other contributors:
Angus Moore [contributor]
See Also
Useful links:
Report bugs at https://github.com/MattCowgill/readrba/issues
Pipe operator
Description
Pipe operator
Usage
lhs %>% rhs
Browse available RBA data series
Description
Use these functions to find the table number or series ID of the data you're interested in.
Usage
browse_rba_series(search_string = "")
browse_rba_tables(search_string = "", refresh = FALSE)
Arguments
search_string |
Word or phrase to search for, such as "gold" or "commodity" or "labour".
If left as |
refresh |
logical; |
Value
A data.frame
(tbl_df
) containing RBA data series/tables that match the search_string
.
Where no search_string
is supplied, the data.frame will contain information
about all RBA series/tables.
The data.frame returned by browse_rba_tables()
includes a column called
readable
. This column takes the value TRUE
if the table is able to be
read by read_rba()
and FALSE
if it cannot be read.
Examples
# Find series that contain 'unemployment'
browse_rba_series("unemployment")
# Or all labour-related series
browse_rba_series("labour")
# Or those related to commodities
browse_rba_series("commodities")
# Or all series
browse_rba_series()
# Or just look for tables that contain the word 'labour'
browse_rba_tables("labour")
# Or all tables
browse_rba_tables()
# To re-scrape the RBA website to ensure you have up-to-date information
# about available tables:
## Not run:
browse_rba_tables(refresh = TRUE)
## End(Not run)
Perform a minimal check to see if a dataframe is formatted in a standard way for an RBA time series spreadsheet. Checks to see if various strings are present in the first column of the DF.
Description
Perform a minimal check to see if a dataframe is formatted in a standard way for an RBA time series spreadsheet. Checks to see if various strings are present in the first column of the DF.
Usage
check_if_rba_ts(df)
Arguments
df |
A data frame |
Value
Logical; TRUE
if df
contains the expected strings in first col;
FALSE
if not.
Obtain the month of the latest RBA SMP forecasts
Description
Obtain the month of the latest RBA SMP forecasts
Usage
latest_forecast_month()
Details
This function returns a length-one date, corresponding to first day of the month of the latest RBA Statement on Monetary Policy forecasts.
Examples
## Not run:
latest_forecast_month()
## End(Not run)
Load the data sheet(s) from an RBA Excel file
Description
Load the data sheet(s) from an RBA Excel file
Usage
load_rba_sheet(filename)
Arguments
filename |
Filename, including path, to an RBA Excel workbook |
Details
Function loads every sheet in the Excel workbook at filename
other than any with names that correspond to known non-data sheets
(eg. "Notes").
Value
list of dataframes
Compile the RBA's public forecasts of key economic variables over time
Description
Compile the RBA's public forecasts of key economic variables over time
Usage
rba_forecasts(
refresh = TRUE,
all_or_latest = c("all", "latest"),
remove_old = TRUE
)
read_forecasts(...)
Arguments
refresh |
logical; default is |
all_or_latest |
character; default is |
remove_old |
logical; default is |
... |
Arguments passed to |
Details
Forecasts are not available for all series on all forecast dates. CPI inflation and GDP growth are included in all forecasts. The unemployment rate is included in most forecasts. Other series are included inconsistently, based on their availability in the underlying source data.
All forecasts issued on or before November 2014 come from Tulip and Wallace (2012), RBA RDP2012-07. Data available: https://www.rba.gov.au/statistics/historical-forecasts.html.
Data from 2015 to August 2018 are scraped from the RBA's quarterly Statement on Monetary Policy (https://www.rba.gov.au/publications/smp/2020/aug/). Note from from Feb 2015 to August 2018 (inclusive) only include a few series; those from November 2018 onwards include more series.
Data from November 2018 to present comes from the published 'Forecasts Archive' file on the RBA website (https://www.rba.gov.au/publications/smp/forecasts-archive.html).
read_forecasts()
is a wrapper around rba_forecasts()
.
Value
A tidy tbl_df
containing 8 columns:
forecast_date
The (approximate) date on which the forecast was published. Note that this is the first day of the publication month, so the
forecast_date
for forecasts in the February 2020 Statement on Monetary Policy isas.Date("2020-02-01")
.date
The date to which the forecast pertains. Note that this is the first day of the final month of the relevant quarter. For example, a forecast of GDP in the June quarter 2021 will be
as.Date("2021-06-01")
.year_qtr
The year and quarter to which the forecast pertains, such as 2019.1.
series
Short, snake_case description of the data series being forecast, such as
gdp_change
orunemp_rate
. These are consistent over time.value
The forecast value, in per cent. For example, if GDP growth is forecast to be 3 per cent, the value will be
3
. Note that where a forecast is given as a range (eg. 3.5-4.5%) thevalue
will be the midpoint of the range (eg. 4%).series_desc
Full description of the series being forecast, as per the RBA website, such as "Real household disposable income". Note that series descriptions are not necessarily consistent over time; the values here are those published by the RBA. The
series
column is consistent over time.source
For recent forecasts, this is 'SMP', meaning the RBA's Statement on Monetary Policy. Forecasts prior to 2014 are sourced from various places; see
Details
.notes
Notes accompanying the forecasts, as per the RBA's website. Note these are identical for item in a given
forecast_date
.
Examples
forecasts <- read_forecasts()
Convenience function to get the RBA's cash rate.
Description
Convenience function to get the RBA's cash rate.
Usage
read_cashrate(type = c("target", "interbank", "both"))
rba_cashrate(...)
Arguments
type |
One of
|
... |
arguments passed to |
Details
Note that in the very early 1990s, the cash rate target was
expressed as a range (eg. "17% to 17.5%"). Where this is the case,
the value returned here (and in read_rba()
) is the mid-point of this range.
If type = 'both'
, note that the returned tbl is tidy/long.
rba_cashrate()
is a wrapper around read_cashrate()
.
Value
A tbl_df
with two columns: date
and cash_rate
.
Drop-in replacement for readxl::read_excel()
that does not infer
file type based on extension
Description
Drop-in replacement for readxl::read_excel()
that does not infer
file type based on extension
Usage
read_excel_noguess(path, ...)
Arguments
path |
Path to the xls/xlsx file. |
... |
Arguments passed to |
Download, import, and tidy statistical tables from the RBA
Description
Download, import, and tidy statistical tables from the RBA
Usage
read_rba(
table_no = NULL,
cur_hist = "current",
series_id = NULL,
path = tempdir(),
update_urls = FALSE
)
read_rba_seriesid(series_id, path = tempdir())
Arguments
table_no |
Character vector of table number(s),
such as |
cur_hist |
Character; valid values are |
series_id |
Optional, character. Specifying Supply unique RBA time series identifier(s).
For example, "GCPIAG" is the identifier for the CPI, so Note that |
path |
Directory in which to save downloaded RBA Excel file(s).
Default is |
update_urls |
Logical; default is Must be either a vector of either length 1 (eg. "
|
Details
read_rba()
downloads, imports and tidies data from statistical
tables published by the Reserve Bank of Australia. You can specify the
requested data using the table_no
or series_id
.
To find the table_no
or series_id
that corresponds to the data you want,
use the functions browse_rba_tables()
and/or browse_rba_series()
. Note
that some historical exchange rate tables do not have table numbers on
the RBA website; they have been assigned table numbers -
see browse_rba_tables("exchange rates").
To see which tables cannot currently be read, run browse_rba_tables(FALSE)
.
read_rba_seriesid()
is a wrapper around read_rba()
.
Certain corporate networks restrict your ability to download files in an R
session. On some of these networks, the "wininet"
method must be used when
downloading files. Users can specify the method that will be used to
download files by setting the "R_READRBA_DL_METHOD"
environment variable.
For example, the following code sets the environment variable for your
current session: Sys.setenv("R_READRBA_DL_METHOD" = "wininet")
You can add "R_READRBA_DL_METHOD"
to your .Rprofile to have this
persist across sessions.
Value
A single tidy tibble containing the requested table(s)
Examples
## Not run:
# Get a single table:
read_rba(table_no = "a1.1")
# Get multiple tables, combined in a tidy tibble:
read_rba(table_no = c("a1.1", "g1"))
# Get both the current and historical versions of a table
read_rba(table_no = c("a1.1", "a1.1"), cur_hist = c("current", "historical"))
# Get data based on the series ID:
read_rba(series_id = "GCPIAG")
# Or, equivalently, use:
read_rba_seriesid("GCPIAG")
# Get multiple series IDs:
read_rba(series_id = c("GCPIAG", "GCPIAGSAQP"))
## End(Not run)
Load and tidy local RBA Excel sheets
Description
Load and tidy local RBA Excel sheets
Usage
read_rba_local(filenames, series_id = NULL)
Arguments
filenames |
Vector of filename(s) (with path) pointing to local RBA Excel sheets |
series_id |
Optional series ID |
Value
A tbl_df
containing tidied RBA Excel sheet(s)
Examples
## Not run:
read_rba_local("data/rba_file.xls")
## End(Not run)
This function checks to see if an Excel file's extension matches its signature; if it does not, the file will be renamed so that the file extension is equal to the signature
Description
This function checks to see if an Excel file's extension matches its signature; if it does not, the file will be renamed so that the file extension is equal to the signature
Usage
rename_excel(filename)
read_html()
safely.
Description
The purpose of this function is to specify a user agent for scraping, to try a second time if a scrape attempt fails, and to return a useful error if the page cannot be scraped.
Usage
safely_read_html(url, ...)
Arguments
url |
url to read with |
... |
arguments passed to |
Value
If the URL is read without error, an XML document
(see ?xml2::read_html
).
Import and tidy forecasts from the published RBA SMP .xlsx file
Not intended to be called directly; call from read_forecasts()
Description
Import and tidy forecasts from the published RBA SMP .xlsx file
Not intended to be called directly; call from read_forecasts()
Usage
scrape_rba_forecasts()
Scrape the RBA site to obtain links to tables
Description
Scrape the RBA site to obtain links to tables
Usage
scrape_table_list(cur_hist = "all")
Arguments
cur_hist |
"current", "historical", or "all" |
Value
A tibble containing the text and URL of XLS/XLSX links
Given series ID(s), find the corresponding table number(s)
Description
Given series ID(s), find the corresponding table number(s)
Usage
tables_from_seriesid(series_id)
Arguments
series_id |
A character vector of RBA series ID(s) |
Tidy a statistical table from the RBA
Description
Tidy a statistical table from the RBA
Usage
tidy_rba(excel_sheet, series_id = NULL)
Arguments
excel_sheet |
Dataframe of RBA spreadsheet. |
series_id |
Optional series ID |
Value
Tidy tibble