Skip to content

Commit

Permalink
Merge branch 'main' into populations
Browse files Browse the repository at this point in the history
  • Loading branch information
Moohan authored Oct 7, 2024
2 parents c09ddff + 4d85123 commit 1addc4c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion R/get_simd_postcode.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ get_simd_postcode <- function(

return(read_file(
simd_postcode_path,
col_select = col_select,
col_select = {{ col_select }},
as_data_frame = as_data_frame
))
}
2 changes: 1 addition & 1 deletion R/get_spd.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ get_spd <- function(

return(read_file(
spd_path,
col_select = col_select,
col_select = {{ col_select }},
as_data_frame = as_data_frame
))
}
4 changes: 2 additions & 2 deletions R/read_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ read_file <- function(path, col_select = NULL, as_data_frame = TRUE, ...) {
))
}

if ((!missing(col_select) || !missing(as_data_frame)) && ext != "parquet") {
if ((!rlang::quo_is_null(rlang::enquo(col_select)) || !missing(as_data_frame)) && ext != "parquet") {
cli::cli_abort(c(
"x" = "{.arg col_select} and/or {.arg as_data_frame} must only be used
when reading a {.field .parquet} file."
Expand All @@ -41,7 +41,7 @@ read_file <- function(path, col_select = NULL, as_data_frame = TRUE, ...) {
"csv" = readr::read_csv(file = path, ..., show_col_types = FALSE),
"parquet" = tibble::as_tibble(arrow::read_parquet(
file = path,
col_select = !!col_select,
col_select = {{ col_select }},
as_data_frame = as_data_frame,
...
))
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-get_simd_postcode.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,17 @@ test_that("col selection works", {
) |>
expect_message()
})

test_that("col selection works with tidyselect", {
expect_named(
get_simd_postcode(col_select = c("pc7", dplyr::starts_with("simd")))
) |>
expect_message()

expect_named(
get_simd_postcode(col_select = dplyr::matches("pc[78]")),
c("pc7", "pc8"),
ignore.order = TRUE
) |>
expect_message()
})
13 changes: 13 additions & 0 deletions tests/testthat/test-get_spd.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,16 @@ test_that("col selection works", {
) |>
expect_message()
})

test_that("col selection works with tidyselect", {
expect_named(
get_spd(col_select = c("pc7", dplyr::starts_with("hb")))
) |>
expect_message()

expect_named(
get_spd(col_select = dplyr::matches("pc[78]")),
c("pc7", "pc8")
) |>
expect_message()
})

0 comments on commit 1addc4c

Please # to comment.