-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cross year tests using SLFhelper WIP
WIP - still need to add write to disk and possibly develop visuals
- Loading branch information
Showing
4 changed files
with
78 additions
and
1 deletion.
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
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,57 @@ | ||
#' Process cross year tests | ||
#' | ||
#' @description Process high level tests (e.g the number of records in each recid) | ||
#' across years. | ||
#' | ||
#' @param year Year of the file to be read, you can specify multiple years | ||
#' which will then be returned as one file. See SLFhelper for more info. | ||
#' | ||
#' @return a tibble with a test summary across years | ||
#' @export | ||
#' | ||
process_tests_cross_year <- function(year) { | ||
ep_file <- read_dev_slf_file(year, | ||
type = "episode", | ||
col_select = c("year", "recid", "anon_chi", "record_keydate1", "record_keydate2") | ||
) | ||
|
||
total_test <- ep_file %>% | ||
dplyr::group_by(.data$year, .data$recid) %>% | ||
dplyr::mutate( | ||
n_records = 1L | ||
) %>% | ||
dplyr::summarise( | ||
n = sum(n_records) | ||
) %>% | ||
dplyr::mutate( | ||
fy_qtr = "total" | ||
) | ||
|
||
qtr_test <- ep_file %>% | ||
dplyr::mutate( | ||
fy_qtr = dplyr::if_else(recid != "PIS", lubridate::quarter(record_keydate1, fiscal_start = 4), NA) | ||
) %>% | ||
dplyr::group_by(.data$year, .data$recid, .data$fy_qtr) %>% | ||
dplyr::mutate( | ||
n_records = 1L | ||
) %>% | ||
dplyr::summarise( | ||
n = sum(n_records) | ||
) %>% | ||
dplyr::mutate( | ||
fy_qtr = as.character(fy_qtr) | ||
) | ||
|
||
join_tests <- dplyr::bind_rows(total_test, qtr_test) %>% | ||
dplyr::arrange(year, recid, fy_qtr) | ||
|
||
pivot_tests <- join_tests %>% | ||
tidyr::pivot_wider( | ||
names_from = c("year", "fy_qtr"), | ||
names_glue = "{year}_qtr_{fy_qtr}", | ||
values_from = "n" | ||
) %>% | ||
dplyr::select(-tidyselect::ends_with("NA")) | ||
|
||
return(pivot_tests) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.