From 99f3587e531d10f691559aa1ee4cf8cf21053361 Mon Sep 17 00:00:00 2001 From: peteowen1 Date: Wed, 7 Feb 2024 11:24:23 +1100 Subject: [PATCH] conditional area_code update only mutate area_code if the column exists also change filtering from across to if_any as dplyr guidlines --- R/seifa.R | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/R/seifa.R b/R/seifa.R index 2003062..0aed079 100644 --- a/R/seifa.R +++ b/R/seifa.R @@ -297,15 +297,18 @@ get_seifa_index_sheet <- function(filename, sheetname, structure = c("sa1", "sa2 col_names = column_names, na = c("", "NA", "-") ) %>% - dplyr::filter(across(ends_with("_code"), ~ !is.na(.x))) %>% + dplyr::filter(if_any(ends_with("_code"), ~ !is.na(.x))) %>% select(-starts_with("blank")) %>% mutate( - area_code = as.character(area_code), structure = structure, year = year ) %>% + mutate(across( + .cols = any_of("area_code"), # Specify the column name + .fns = ~ as.character(.) # Conditionally convert to character + )) %>% relocate(structure) }) - + return(df) }