Skip to content

Commit

Permalink
fix age issue in multiple years
Browse files Browse the repository at this point in the history
  • Loading branch information
lizihao-anu committed Sep 17, 2024
1 parent daa6263 commit 20cc89d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions R/read_slf.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
)
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-multiple_years.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) %>%
Expand Down

0 comments on commit 20cc89d

Please sign in to comment.