Skip to content

Commit 1addc4c

Browse files
authored
Merge branch 'main' into populations
2 parents c09ddff + 4d85123 commit 1addc4c

5 files changed

Lines changed: 31 additions & 4 deletions

File tree

R/get_simd_postcode.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ get_simd_postcode <- function(
4141

4242
return(read_file(
4343
simd_postcode_path,
44-
col_select = col_select,
44+
col_select = {{ col_select }},
4545
as_data_frame = as_data_frame
4646
))
4747
}

R/get_spd.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ get_spd <- function(
2929

3030
return(read_file(
3131
spd_path,
32-
col_select = col_select,
32+
col_select = {{ col_select }},
3333
as_data_frame = as_data_frame
3434
))
3535
}

R/read_file.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ read_file <- function(path, col_select = NULL, as_data_frame = TRUE, ...) {
2929
))
3030
}
3131

32-
if ((!missing(col_select) || !missing(as_data_frame)) && ext != "parquet") {
32+
if ((!rlang::quo_is_null(rlang::enquo(col_select)) || !missing(as_data_frame)) && ext != "parquet") {
3333
cli::cli_abort(c(
3434
"x" = "{.arg col_select} and/or {.arg as_data_frame} must only be used
3535
when reading a {.field .parquet} file."
@@ -41,7 +41,7 @@ read_file <- function(path, col_select = NULL, as_data_frame = TRUE, ...) {
4141
"csv" = readr::read_csv(file = path, ..., show_col_types = FALSE),
4242
"parquet" = tibble::as_tibble(arrow::read_parquet(
4343
file = path,
44-
col_select = !!col_select,
44+
col_select = {{ col_select }},
4545
as_data_frame = as_data_frame,
4646
...
4747
))

tests/testthat/test-get_simd_postcode.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,17 @@ test_that("col selection works", {
2626
) |>
2727
expect_message()
2828
})
29+
30+
test_that("col selection works with tidyselect", {
31+
expect_named(
32+
get_simd_postcode(col_select = c("pc7", dplyr::starts_with("simd")))
33+
) |>
34+
expect_message()
35+
36+
expect_named(
37+
get_simd_postcode(col_select = dplyr::matches("pc[78]")),
38+
c("pc7", "pc8"),
39+
ignore.order = TRUE
40+
) |>
41+
expect_message()
42+
})

tests/testthat/test-get_spd.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,16 @@ test_that("col selection works", {
2626
) |>
2727
expect_message()
2828
})
29+
30+
test_that("col selection works with tidyselect", {
31+
expect_named(
32+
get_spd(col_select = c("pc7", dplyr::starts_with("hb")))
33+
) |>
34+
expect_message()
35+
36+
expect_named(
37+
get_spd(col_select = dplyr::matches("pc[78]")),
38+
c("pc7", "pc8")
39+
) |>
40+
expect_message()
41+
})

0 commit comments

Comments
 (0)