From 67728fa5b9cfb3ef18d37371318d4f83b5c9a762 Mon Sep 17 00:00:00 2001 From: nicolc11 Date: Tue, 23 Jul 2024 08:28:52 +0100 Subject: [PATCH 1/5] Fix for col_select. --- R/read_file.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/read_file.R b/R/read_file.R index e1bf0ce..55829b0 100644 --- a/R/read_file.R +++ b/R/read_file.R @@ -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, ... )) From cb2ae09b80f60d3e70a7faa8daf62bdc0158fa2c Mon Sep 17 00:00:00 2001 From: James McMahon Date: Tue, 23 Jul 2024 09:25:25 +0100 Subject: [PATCH 2/5] Add tests to use tidyselect --- tests/testthat/test-get_simd_postcode.R | 13 +++++++++++++ tests/testthat/test-get_spd.R | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/tests/testthat/test-get_simd_postcode.R b/tests/testthat/test-get_simd_postcode.R index ba695d2..b628457 100644 --- a/tests/testthat/test-get_simd_postcode.R +++ b/tests/testthat/test-get_simd_postcode.R @@ -26,3 +26,16 @@ 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") + ) |> + expect_message() +}) diff --git a/tests/testthat/test-get_spd.R b/tests/testthat/test-get_spd.R index 1a2938f..ff67a7a 100644 --- a/tests/testthat/test-get_spd.R +++ b/tests/testthat/test-get_spd.R @@ -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() +}) From 863c67ae681bbc8d1b4a765ebcf182b6e639fbef Mon Sep 17 00:00:00 2001 From: nicolc11 Date: Thu, 25 Jul 2024 09:56:46 +0100 Subject: [PATCH 3/5] Fix for col selecting. --- R/get_simd_postcode.R | 2 +- R/get_spd.R | 2 +- R/read_file.R | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/R/get_simd_postcode.R b/R/get_simd_postcode.R index 382afaf..eda861c 100644 --- a/R/get_simd_postcode.R +++ b/R/get_simd_postcode.R @@ -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 )) } diff --git a/R/get_spd.R b/R/get_spd.R index 0317936..9869929 100644 --- a/R/get_spd.R +++ b/R/get_spd.R @@ -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 )) } diff --git a/R/read_file.R b/R/read_file.R index 55829b0..c287ffd 100644 --- a/R/read_file.R +++ b/R/read_file.R @@ -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_missing(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." From 4f14fc514f098f5725e26f1f56bf032710b2a870 Mon Sep 17 00:00:00 2001 From: James McMahon Date: Thu, 25 Jul 2024 14:16:28 +0100 Subject: [PATCH 4/5] Don't care about variable order in tests --- tests/testthat/test-get_simd_postcode.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-get_simd_postcode.R b/tests/testthat/test-get_simd_postcode.R index b628457..465824f 100644 --- a/tests/testthat/test-get_simd_postcode.R +++ b/tests/testthat/test-get_simd_postcode.R @@ -35,7 +35,8 @@ test_that("col selection works with tidyselect", { expect_named( get_simd_postcode(col_select = dplyr::matches("pc[78]")), - c("pc7", "pc8") + c("pc7", "pc8"), + ignore.order = TRUE ) |> expect_message() }) From 34220acd1cb9bf2eeb37b83b6f46ae1282f4a12a Mon Sep 17 00:00:00 2001 From: nicolc11 Date: Fri, 26 Jul 2024 10:35:54 +0100 Subject: [PATCH 5/5] Small fix for tests. --- R/read_file.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/read_file.R b/R/read_file.R index c287ffd..9796966 100644 --- a/R/read_file.R +++ b/R/read_file.R @@ -29,7 +29,7 @@ read_file <- function(path, col_select = NULL, as_data_frame = TRUE, ...) { )) } - if ((!rlang::quo_is_missing(rlang::enquo(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."