Skip to content

Commit

Permalink
Merge pull request #132 from atorus-research/131-0-row-bug
Browse files Browse the repository at this point in the history
131 0 row bug
  • Loading branch information
mstackhouse authored Nov 7, 2023
2 parents 0776d9c + daafa49 commit f7d07fa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 5 additions & 1 deletion R/denom.R
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ get_denom_total <- function(.data, denoms_by, denoms_df,
# Filter denoms dataset
vars_in_denoms <- denoms_by[map_lgl(denoms_by, ~ as_name(.) %in% names(denoms_df))]
filter_logic <- map(vars_in_denoms, function(x) {
expr(!!sym(as_name(x)) == !!unique(.data[, as_name(x)])[[1]])
if (nrow(.data) > 0) {
expr(!!sym(as_name(x)) == !!unique(.data[, as_name(x)])[[1]])
} else {
FALSE
}
})

sums <- denoms_df %>%
Expand Down
21 changes: 21 additions & 0 deletions tests/testthat/test-denom.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,24 @@ test_that("this_denom can be called after a group_by and gives totals", {

expect_equal(df2, tibble(total = rep(c(15, 12, 5), c(15, 12, 5))))
})

test_that("can build when data has no rows and population data is set (#131)", {

load(test_path("adae.Rdata"))
load(test_path("adsl.Rdata"))

t <- adae %>%
tplyr_table(TRTA) %>%
set_pop_data(adsl) %>%
set_pop_treat_var(TRT01A) %>%
add_layer(
group_count(
TRTEMFL,
where = TRTEMFL == "Y" & AESER == "Y" & AEREL == "REMOTE"
) %>%
set_distinct_by(USUBJID)
)

expect_no_error(build(t))

})

0 comments on commit f7d07fa

Please sign in to comment.