Skip to content

Commit

Permalink
Merge pull request #162 from atorus-research/gh_issue_147
Browse files Browse the repository at this point in the history
Add object type asserssion into set_denom_where
  • Loading branch information
mstackhouse committed Dec 18, 2023
2 parents 9a17f5c + 49ebf7a commit bb2dc13
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions R/count_bindings.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 either "tplyr_layer" or "tplyr_table"', call.=FALSE)
}

assert_that(is_logical_or_call(denom_where),
msg = "The `where` parameter must contain subsetting logic (enter without quotes)")

Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-count.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(t1) <- "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(
Expand Down

0 comments on commit bb2dc13

Please sign in to comment.