Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for col_select. #9

Merged
merged 5 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
))
}

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 @@
"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()
})
Loading