Skip to content

Commit

Permalink
Merge pull request #9 from Public-Health-Scotland/col_select_fix
Browse files Browse the repository at this point in the history
Fix for col_select.
  • Loading branch information
Moohan authored Jul 29, 2024
2 parents eef04c1 + 34220ac commit 4d85123
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") {

Check warning on line 32 in R/read_file.R

View workflow job for this annotation

GitHub Actions / lint

file=R/read_file.R,line=32,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 103 characters.
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 4d85123

Please sign in to comment.