diff --git a/DESCRIPTION b/DESCRIPTION index f799c8c..800ff97 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: slfhelper Title: Useful functions for working with the Source Linkage Files -Version: 0.10.4 +Version: 0.10.5 Authors@R: c( person("Public Health Scotland", , , "phs.source@phs.scot", role = "cph"), person("James", "McMahon", , "james.mcmahon@phs.scot", role = c("aut"), diff --git a/NEWS.md b/NEWS.md index 5804177..8471c8e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,6 @@ +# slfhelper 0.10.5 +* Bug - fix age as an integer when reading multiple years + # slfhelper 0.10.4 * Bug - Fix build tests * New feature - Additional documentation diff --git a/R/read_slf.R b/R/read_slf.R index 622d9b8..ad9a167 100644 --- a/R/read_slf.R +++ b/R/read_slf.R @@ -62,6 +62,7 @@ read_slf <- function( # Check if recid/hscp is among the selected columns recid_present <- "recid" %in% selected_columns hscp_present <- "hscp2018" %in% selected_columns + age_present <- "age" %in% selected_columns # check if we need add extra recid/hscp to do filter # remember to remove recid/hscp later @@ -109,6 +110,11 @@ read_slf <- function( slf_table <- slf_table %>% dplyr::select(-c("hscp2018")) } + if (age_present){ + slf_table <- slf_table %>% + dplyr::mutate(age = as.integer(.data$age)) + } + return(slf_table) } ) @@ -184,10 +190,6 @@ read_slf_episode <- function( data <- data %>% dplyr::mutate(keytime2 = hms::as_hms(.data$keytime2)) } - if ("age" %in% names(data)) { - data <- data %>% - dplyr::mutate(age = as.integer(age)) - } return(data) } diff --git a/tests/testthat/test-multiple_years.R b/tests/testthat/test-multiple_years.R index 842d37f..7d7a0a8 100644 --- a/tests/testthat/test-multiple_years.R +++ b/tests/testthat/test-multiple_years.R @@ -6,7 +6,7 @@ test_that("read multiple years works for individual file", { # Read in multiple years indiv <- read_slf_individual(c("1718", "1819"), - col_select = c("year", "anon_chi") + col_select = c("year", "anon_chi", "age") ) %>% dplyr::group_by(year) %>% dplyr::slice_sample(n = 50) %>%