From 1ee583999a35449955ccb85c9db3521e0422803a Mon Sep 17 00:00:00 2001 From: Shiyu Chen Date: Fri, 15 Dec 2023 19:25:29 +0000 Subject: [PATCH 1/4] Add object type asserssion --- R/count_bindings.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/count_bindings.R b/R/count_bindings.R index 5601cd90..660ebbdd 100644 --- a/R/count_bindings.R +++ b/R/count_bindings.R @@ -576,6 +576,10 @@ set_outer_sort_position <- function(e, outer_sort_position) { set_denom_where <- function(e, denom_where) { denom_where <- enquo(denom_where) + if (!(inherits(e, 'tplyr_layer') | inherits(e, 'tplyr_table'))) { + stop('Object type should be ', call.=FALSE) + } + assert_that(is_logical_or_call(denom_where), msg = "The `where` parameter must contain subsetting logic (enter without quotes)") From 4601d34ccce8cab3e28ee12878faefefb6018cd6 Mon Sep 17 00:00:00 2001 From: Shiyu Chen Date: Fri, 15 Dec 2023 19:49:24 +0000 Subject: [PATCH 2/4] error message update --- R/count_bindings.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/count_bindings.R b/R/count_bindings.R index 660ebbdd..291779e3 100644 --- a/R/count_bindings.R +++ b/R/count_bindings.R @@ -577,7 +577,7 @@ set_denom_where <- function(e, denom_where) { denom_where <- enquo(denom_where) if (!(inherits(e, 'tplyr_layer') | inherits(e, 'tplyr_table'))) { - stop('Object type should be ', call.=FALSE) + stop('Object type should be either "tplyr_layer" or "tplyr_table"', call.=FALSE) } assert_that(is_logical_or_call(denom_where), From 2ba66194d372fbd3ec7f890f4266f0321e72e6f5 Mon Sep 17 00:00:00 2001 From: Shiyu Chen Date: Fri, 15 Dec 2023 22:44:22 +0000 Subject: [PATCH 3/4] Added a test for object check --- tests/testthat/test-count.R | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/testthat/test-count.R b/tests/testthat/test-count.R index c61f0d29..a8d2d62a 100644 --- a/tests/testthat/test-count.R +++ b/tests/testthat/test-count.R @@ -440,6 +440,17 @@ test_that("set_denom_where works as expected", { expect_snapshot_output(dput(t13)) }) +test_that("set_denom_where errors for incompatible object type", { + t1 <- tplyr_table(mtcars, gear) + + # Modify the object type to make it incompatible + class(t) <- "environment" + + # Function errors + t1 <- set_denom_where(t1, mpg != 21) %>% + expect_error("Object type should be") +}) + test_that("missing counts can be set without a format and it inherits the layer format", { t1 <- tplyr_table(mtcars, gear) %>% add_layer( From 49ebf7a9c5cba5d4b0d2d29e27ce46e9b96adc0d Mon Sep 17 00:00:00 2001 From: Shiyu Chen Date: Fri, 15 Dec 2023 22:45:29 +0000 Subject: [PATCH 4/4] object name update --- tests/testthat/test-count.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-count.R b/tests/testthat/test-count.R index a8d2d62a..3a248a2e 100644 --- a/tests/testthat/test-count.R +++ b/tests/testthat/test-count.R @@ -444,7 +444,7 @@ test_that("set_denom_where errors for incompatible object type", { t1 <- tplyr_table(mtcars, gear) # Modify the object type to make it incompatible - class(t) <- "environment" + class(t1) <- "environment" # Function errors t1 <- set_denom_where(t1, mpg != 21) %>%