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

Add object type asserssion into set_denom_where #162

Merged
merged 4 commits into from
Dec 18, 2023
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
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
Loading