Skip to content

Commit

Permalink
Style package
Browse files Browse the repository at this point in the history
  • Loading branch information
lizihao-anu authored and github-actions[bot] committed Sep 6, 2024
1 parent ff70393 commit d594667
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
29 changes: 15 additions & 14 deletions R/read_slf.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ read_slf <- function(
file_path,
function(file_path) {
slf_table <- arrow::read_parquet(file_path,
col_select = {{ col_select }},
as_data_frame = FALSE)
col_select = {{ col_select }},
as_data_frame = FALSE
)

selected_columns <- names(slf_table)

Expand Down Expand Up @@ -102,10 +103,10 @@ read_slf <- function(

# remove hscp recid
if (add_extra_recid) {
slf_table = slf_table %>% dplyr::select(-c("recid"))
slf_table <- slf_table %>% dplyr::select(-c("recid"))
}
if (add_extra_hscp) {
slf_table = slf_table %>% dplyr::select(-c("hscp2018"))
slf_table <- slf_table %>% dplyr::select(-c("hscp2018"))
}

return(slf_table)
Expand Down Expand Up @@ -160,17 +161,17 @@ read_slf_episode <- function(
}
# TODO add option to drop blank CHIs?

data = read_slf(
year = year,
col_select = {{ col_select }},
file_version = "episode",
partnerships = unique(partnerships),
recids = unique(recids),
as_data_frame = as_data_frame,
dev = dev
)
data <- read_slf(
year = year,
col_select = {{ col_select }},
file_version = "episode",
partnerships = unique(partnerships),
recids = unique(recids),
as_data_frame = as_data_frame,
dev = dev
)

if(("keytime1" %in% names(data) | "keytime2" %in% names(data)) & !as_data_frame){
if (("keytime1" %in% names(data) | "keytime2" %in% names(data)) & !as_data_frame) {
warning('"keytime1" and "keytime2" does not work with `as_data_frame = FALSE` at the moment. So force as_data_frame = TRUE')
data <- data %>%
dplyr::collect()
Expand Down
14 changes: 8 additions & 6 deletions tests/testthat/test-tidyselect_columns.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ test_that("tidyselect helpers work for column selection in the episode file", {
read_slf_episode("1920", col_select = c("year", dplyr::starts_with("dd"))),
c("year", "dd_responsible_lca", "dd_quality")
)
expect_gte(read_slf_episode(
year = "1920",
recids = c("CH", "HC", "DD"),
col_select = c(ep_file_vars[c(1:5, 100)], "hscp2018")
) %>% nrow(),
100)
expect_gte(
read_slf_episode(
year = "1920",
recids = c("CH", "HC", "DD"),
col_select = c(ep_file_vars[c(1:5, 100)], "hscp2018")
) %>% nrow(),
100
)
})

test_that("col_select works when columns are added", {
Expand Down

0 comments on commit d594667

Please sign in to comment.