Skip to content

Commit

Permalink
Fix for anon_chi missing (#752)
Browse files Browse the repository at this point in the history
* Fix for anon_chi missing

`slfhelper::get_anon_chi` converts `NA` to "TkE=" which would then be converted back to "e1" 🤯

This fixes that by making NA CHIs blank `""`, then making blank anon_chis NA after.

slfhelper should be updated so that it always converts NA to NA.

* Update run_episode_file.R

* Style code

* Update documentation

---------

Co-authored-by: Moohan <[email protected]>
  • Loading branch information
Moohan and Moohan authored Jul 19, 2023
1 parent ee7445b commit 74109bf
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 20 deletions.
20 changes: 10 additions & 10 deletions R/run_episode_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ run_episode_file <- function(
)
) %>%
# Check chi is valid using phsmethods function
# If the CHI is invalid for whatever reason, set the CHI to blank string
# If the CHI is invalid for whatever reason, set the CHI to NA
dplyr::mutate(
chi = dplyr::if_else(
phsmethods::chi_check(.data$chi) != "Valid CHI",
Expand All @@ -110,11 +110,11 @@ run_episode_file <- function(
load_ep_file_vars(year)

if (anon_chi_out) {
episode_file <- slfhelper::get_anon_chi(
episode_file,
chi_var = "chi",
drop = TRUE
)
# TODO When slfhelper is updated remove the unnecessary code
episode_file <- episode_file %>%
tidyr::replace_na(list(chi = "")) %>%
slfhelper::get_anon_chi() %>%
dplyr::mutate(anon_chi = dplyr::na_if(.data$anon_chi, ""))
}

if (write_to_disk) {
Expand All @@ -135,10 +135,10 @@ run_episode_file <- function(

#' Store the unneeded episode file variables
#'
#' @param data The in progress episode file data.
#' @param data The in-progress episode file data.
#' @inheritParams run_episode_file
#' @param vars_to_keep a character vector of variable to keep, all others will
#' be stored.
#' @param vars_to_keep a character vector of the variables to keep, all others
#' will be stored.
#'
#' @return `data` with only the `vars_to_keep` kept
store_ep_file_vars <- function(data, year, vars_to_keep) {
Expand Down Expand Up @@ -324,7 +324,7 @@ create_cost_inc_dna <- function(data) {
#'
#' @return The data unchanged (the cohorts are written to disk)
create_cohort_lookups <- function(data, year, update = latest_update()) {
# Use future so the cohorts can be create simultaneously (in parallel)
# Use future so the cohorts can be created simultaneously (in parallel)
future::plan(strategy = future.callr::callr, .skip = TRUE)
options(future.globals.maxSize = 21474836480)

Expand Down
2 changes: 1 addition & 1 deletion man/correct_cij_vars.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/create_cohort_lookups.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/create_cost_inc_dna.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/fill_missing_cij_markers.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/join_cohort_lookups.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/join_sparra_hhg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/load_ep_file_vars.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/store_ep_file_vars.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 74109bf

Please sign in to comment.