From 1571adec2af61bbcc6f007979ab88308f3861d5c Mon Sep 17 00:00:00 2001 From: James McMahon Date: Thu, 20 Jul 2023 19:17:11 +0100 Subject: [PATCH] Fix for years with no DN data 21/22 and 22/23 we're failing because they didn't have `total_no_dn_contacts` this is a bit of a crude fix but should work for any year, and if the variable doesn't exist in the episode file it will be created as `NA` in the individual file. --- R/create_individual_file.R | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/R/create_individual_file.R b/R/create_individual_file.R index 675e2066a..561f0ed3b 100644 --- a/R/create_individual_file.R +++ b/R/create_individual_file.R @@ -25,7 +25,7 @@ create_individual_file <- function( } individual_file <- episode_file %>% - dplyr::select( + dplyr::select(dplyr::any_of(c( "year", "chi", "dob", @@ -57,7 +57,7 @@ create_individual_file <- function( "hc_hours_annual", "hc_reablement", "ooh_case_id" - ) %>% + ))) %>% remove_blank_chi() %>% add_cij_columns() %>% add_all_columns() %>% @@ -321,9 +321,21 @@ add_ooh_columns <- function(episode_file, prefix, condition) { #' @inheritParams add_acute_columns add_dn_columns <- function(episode_file, prefix, condition) { condition <- substitute(condition) - episode_file %>% - add_standard_cols(prefix, condition, episode = TRUE, cost = TRUE) %>% - dplyr::mutate("{prefix}_contacts" := dplyr::if_else(eval(condition), .data$total_no_dn_contacts, NA_integer_)) + if ("total_no_dn_contacts" %in% names(episode_file)) { + episode_file %>% + add_standard_cols(prefix, condition, episode = TRUE, cost = TRUE) %>% + dplyr::mutate( + "{prefix}_contacts" := dplyr::if_else( + eval(condition), + .data$total_no_dn_contacts, + NA_integer_ + ) + ) + } else { + episode_file %>% + add_standard_cols(prefix, condition, episode = TRUE, cost = TRUE) %>% + dplyr::mutate("{prefix}_contacts" := NA_integer_) + } } #' Add CMH columns