-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from MattCowgill/dev
stable 0.0.2
- Loading branch information
Showing
65 changed files
with
3,173 additions
and
320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag. | ||
# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions | ||
on: [push, pull_request] | ||
|
||
name: R-CMD-check-windows | ||
|
||
jobs: | ||
R-CMD-check: | ||
runs-on: windows-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: r-lib/actions/setup-r@master | ||
- name: Install dependencies | ||
run: | | ||
install.packages(c("remotes", "rcmdcheck")) | ||
remotes::install_deps(dependencies = TRUE) | ||
shell: Rscript {0} | ||
- name: Check | ||
run: rcmdcheck::rcmdcheck(args = "--no-manual", error_on = "error") | ||
shell: Rscript {0} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.Rproj.user | ||
.Rhistory | ||
.RData | ||
inst/doc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export("%>%") | ||
export(browse_rba_series) | ||
export(browse_rba_tables) | ||
export(read_rba) | ||
export(read_rba_local) | ||
export(read_rba_seriesid) | ||
export(tidy_rba) | ||
importFrom(dplyr,"%>%") | ||
importFrom(rlang,.data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# readrba 0.0.2 | ||
* Can now use `series_id` argument to `read_rba()` to fetch based on series ID(s) | ||
* Examine available RBA data using `browse_rba_series()` and `browse_rba_tables()` | ||
* `cur_hist = "all"` no longer allowed | ||
* Some non-standard tables now able to be tidied | ||
* Added a `NEWS.md` file to track changes to the package. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#' Browse available RBA data series | ||
#' | ||
#' @param search_string Word or phrase to search for, such as "gold" or "commodity" or "labour". | ||
#' If left as `""`, the function will return all series. | ||
#' @return A `data.frame` (`tbl_df`) containing RBA data series/tables that match the `search_string`. | ||
#' | ||
#' @export | ||
#' @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() | ||
#' @rdname browse_rba | ||
browse_rba_series <- function(search_string = "") { | ||
do_rba_browse( | ||
search_string = search_string, | ||
lookup_table = series_list | ||
) | ||
} | ||
|
||
#' @export | ||
#' @rdname browse_rba | ||
browse_rba_tables <- function(search_string = "") { | ||
do_rba_browse( | ||
search_string = search_string, | ||
lookup_table = table_list | ||
) | ||
} | ||
|
||
#' @noRd | ||
#' @keywords internal | ||
do_rba_browse <- function(search_string, lookup_table) { | ||
row_any <- function(x) rowSums(x) > 0 | ||
|
||
dplyr::filter( | ||
lookup_table, | ||
row_any(dplyr::across( | ||
dplyr::everything(), | ||
~ grepl(search_string, ., ignore.case = TRUE) | ||
)) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
# Functions to prepare Excel sheets with non-standard formatting prior | ||
# to tidying them using the `tidy_rba_normal()` function | ||
|
||
#' Function to wrangle historical yields data to get it in the standard format | ||
#' Called indirectly from tidy_rba() | ||
#' @param excel_sheet Excel sheet with no tidying done | ||
#' @keywords internal | ||
|
||
prelim_tidy_old_f16 <- function(excel_sheet) { | ||
n_col <- ncol(excel_sheet) | ||
|
||
issue_id <- as.character(excel_sheet[3, 2:n_col]) | ||
|
||
bond_type <- dplyr::case_when( | ||
substr(issue_id, 1, 2) == "TB" ~ | ||
"Treasury Bonds ", | ||
substr(issue_id, 1, 2) == "TI" ~ | ||
"Treasury Indexed Bonds ", | ||
TRUE ~ NA_character_ | ||
) | ||
|
||
bond_num <- ifelse(issue_id == "NA", | ||
NA_character_, | ||
substr(issue_id, 3, nchar(issue_id)) | ||
) | ||
|
||
coupon <- as.character(excel_sheet[4, 2:n_col]) | ||
maturity <- as.character(excel_sheet[5, 2:n_col]) | ||
last_updated <- as.character(excel_sheet[8, 2:n_col]) | ||
source <- as.character(excel_sheet[9, 2:n_col]) | ||
mnemonic <- as.character(excel_sheet[10, 2:n_col]) | ||
|
||
new_title <- c( | ||
"Title", | ||
bond_type | ||
) | ||
|
||
excel_date_to_string <- function(x) { | ||
x <- ifelse(x == "NA", NA_character_, x) | ||
x <- as.numeric(x) | ||
x <- as.Date(x, origin = "1899-12-30") | ||
x <- format(x, "%d-%b-%Y") | ||
} | ||
|
||
new_description <- c( | ||
"Description", | ||
paste0( | ||
bond_type, | ||
bond_num, "\n", | ||
suppressWarnings(as.numeric(coupon)) * 100, "%\n", | ||
excel_date_to_string(maturity) | ||
) | ||
) | ||
|
||
new_description <- ifelse(grepl("NA", new_description), | ||
NA_character_, | ||
new_description | ||
) | ||
|
||
new_frequency <- c("Frequency", rep("Daily", n_col - 1)) | ||
new_type <- c("Type", rep("Original", n_col - 1)) | ||
new_units <- c("Units", rep("Units", n_col - 1)) | ||
new_source <- c("Source", source) | ||
new_pub_date <- c("Publication date", last_updated) | ||
new_series_id <- c("Series ID", mnemonic) | ||
|
||
new_metadata <- purrr::map( | ||
list( | ||
new_title, new_description, new_frequency, new_type, | ||
new_units, new_source, new_pub_date, new_series_id | ||
), | ||
~ setNames(.x, paste0("V", 0:(n_col - 1))) | ||
) %>% | ||
dplyr::bind_rows() | ||
|
||
names(new_metadata) <- names(excel_sheet) | ||
|
||
new_sheet <- rbind(new_metadata, excel_sheet[-(1:10), ]) | ||
|
||
new_sheet | ||
} | ||
|
||
#' Function to wrangle historical F2 table to get it in the standard format | ||
#' Called indirectly from tidy_rba() | ||
#' @param excel_sheet Excel sheet with no tidying done | ||
#' @keywords internal | ||
|
||
prelim_tidy_old_f2 <- function(excel_sheet) { | ||
|
||
# fill_blank() adapted from {zoo} - note that this version removes leading NAs | ||
fill_blanks <- function(x) { | ||
L <- !is.na(x) | ||
c(x[L])[cumsum(L)] | ||
} | ||
|
||
issuer <- as.character(excel_sheet[3, ]) | ||
issuer <- fill_blanks(issuer) | ||
issuer <- gsub("Australian Government", "Commonwealth Government", issuer, | ||
fixed = T | ||
) | ||
|
||
maturity <- as.character(excel_sheet[4, ]) | ||
maturity <- maturity[!is.na(maturity)] | ||
maturity <- gsub(" yrs", " years", maturity) | ||
|
||
title <- paste(issuer, maturity, "bond", sep = " ") | ||
title <- gsub("years", "year", title) | ||
new_title <- c("Title", title) | ||
|
||
description <- paste("Yields on", | ||
issuer, "bonds,", | ||
maturity, "maturity", | ||
sep = " " | ||
) | ||
new_description <- c("Description", description) | ||
|
||
n_rows <- nrow(excel_sheet) | ||
n_col <- ncol(excel_sheet) | ||
max_date <- as.Date(as.numeric(excel_sheet[n_rows, 1]), origin = "1899-12-30") | ||
min_date <- as.Date(as.numeric(excel_sheet[11, 1]), origin = "1899-12-30") | ||
approx_days_per_row <- trunc(as.numeric(max_date - min_date) / n_rows) | ||
|
||
frequency <- ifelse(approx_days_per_row == 1, "Daily", "Monthly") | ||
new_frequency <- c("Frequency", rep(frequency, n_col - 1)) | ||
|
||
new_type <- c("Type", rep("Original", n_col - 1)) | ||
|
||
new_units <- c("Units", rep("Per cent per annum", n_col - 1)) | ||
|
||
new_source <- as.character(excel_sheet[9, ]) | ||
|
||
pub_date <- as.character(excel_sheet[8, ]) | ||
new_pub_date <- gsub("Last updated:", "Publish date", pub_date) | ||
|
||
series_id <- as.character(excel_sheet[10, ]) | ||
new_series_id <- gsub("Mnemonic", "Series ID", series_id) | ||
|
||
new_metadata <- purrr::map( | ||
list( | ||
new_title, new_description, new_frequency, new_type, | ||
new_units, new_source, new_pub_date, new_series_id | ||
), | ||
~ setNames(.x, paste0("V", 0:(n_col - 1))) | ||
) %>% | ||
dplyr::bind_rows() | ||
|
||
names(new_metadata) <- names(excel_sheet) | ||
|
||
new_sheet <- rbind(new_metadata, excel_sheet[-(1:10), ]) | ||
|
||
new_sheet | ||
} |
Oops, something went wrong.