From 6b3f3d45c1174f7382049c6311614ccf14551685 Mon Sep 17 00:00:00 2001 From: almac2022 Date: Sun, 20 Oct 2024 10:12:26 -0700 Subject: [PATCH] close #8 by customizing when to capitalize or lower case bcdata_record_id s --- R/rfp_bcd_get_data.R | 12 ++++++++++-- tests/testthat/test-rfp_bcd_get_data.R | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/R/rfp_bcd_get_data.R b/R/rfp_bcd_get_data.R index c69d25e..33d4dde 100644 --- a/R/rfp_bcd_get_data.R +++ b/R/rfp_bcd_get_data.R @@ -22,6 +22,7 @@ #' @importFrom glue glue #' @importFrom chk chk_string chk_character #' @importFrom rlang sym +#' @importFrom stringr str_to_upper str_to_lower #' @family source bcdata #' @examples #' \dontrun{ @@ -61,9 +62,16 @@ rfp_bcd_get_data <- function( cli::cli_abort(message = "col_filter_value cannot be NULL when col_filter is provided.") } - # convert column names and bc_record_id to uppercase - bcdata_record_id <- stringr::str_to_upper(bcdata_record_id) + # Check if there is a period in the input string to deal with capitilization issues + if (grepl("\\.", bcdata_record_id)) { + # Convert to uppercase if there is a period + bcdata_record_id <- stringr::str_to_upper(bcdata_record_id) + } else { + # Convert to lowercase if there is no period + bcdata_record_id <- stringr::str_to_lower(bcdata_record_id) + } + # convert column names to uppercase if(!is.null(col_filter)){ col_filter <- stringr::str_to_upper(col_filter) } diff --git a/tests/testthat/test-rfp_bcd_get_data.R b/tests/testthat/test-rfp_bcd_get_data.R index 179e05e..5ebf44d 100644 --- a/tests/testthat/test-rfp_bcd_get_data.R +++ b/tests/testthat/test-rfp_bcd_get_data.R @@ -12,6 +12,22 @@ test_that("returns result when col_filter and col_filter_value provided", { "data.frame") }) + +test_that("can provide lower case schema.table", { + expect_s3_class( + rfp_bcd_get_data(bcdata_record_id = "whse_imagery_and_base_maps.gsr_airports_svw", col_filter = 'AIRPORT_NAME', + col_filter_value = "Duncan Airport"), + "data.frame") +}) + +test_that("can provide upper case schema.table", { + expect_s3_class( + rfp_bcd_get_data(bcdata_record_id = "WHSE_IMAGERY_AND_BASE_MAPS.GSR_AIRPORTS_SVW", col_filter = 'AIRPORT_NAME', + col_filter_value = "Duncan Airport"), + "data.frame") +}) + + test_that("returns error when col_filter_value provided not present", { expect_error( rfp_bcd_get_data(bcdata_record_id = "bc-airports", col_filter = 'AIRPORT_NAME',