Skip to content

Commit

Permalink
new version passes the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dsweber2 committed Jul 31, 2024
1 parent 7d22ef8 commit acc40bd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
7 changes: 3 additions & 4 deletions R/step_epi_slide.R
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ bake.step_epi_slide <- function(object, new_data, ...) {
}
if (any(vapply(c(mean, sum), \(x) identical(x, object$.f), logical(1L)))) {
cli_warn(
c("There is an optimized version of both mean and sum. See `step_epi_slide_mean`, `step_epi_slide_sum`, or `step_epi_slide_opt`."
),
c("There is an optimized version of both mean and sum. See `step_epi_slide_mean`, `step_epi_slide_sum`, or `step_epi_slide_opt`."),
class = "epipredict__step_epi_slide__optimized_version"
)
}
Expand Down Expand Up @@ -209,9 +208,9 @@ epi_slide_wrapper <- function(new_data, before, after, columns, fns, fn_names, g
col_name <- cols_fns[[comp_i, "col_name"]]
fn_name <- cols_fns[[comp_i, "fn_name"]]
fn <- cols_fns[[comp_i, "fn"]][[1L]]
result_name <- paste(name_prefix, fn_name, col_name, sep="_")
result_name <- paste(name_prefix, fn_name, col_name, sep = "_")
result <- new_data %>%
group_by(across(group_keys)) %>%
group_by(across(all_of(group_keys))) %>%
epi_slide(
before = before,
after = after,
Expand Down
28 changes: 17 additions & 11 deletions tests/testthat/test-step_epi_slide.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ test_that("epi_slide handles classed before/after", {
prep(edf) %>%
bake(new_data = NULL),
regexp = "There is an optimized version"
)
)
expect_equal(baseline[[4]], rolled_before)

expect_warning(
Expand All @@ -70,7 +70,7 @@ test_that("epi_slide handles classed before/after", {
prep(edf) %>%
bake(new_data = NULL),
regexp = "There is an optimized version"
)
)
expect_warning(
cbefore <- r %>%
step_epi_slide(value, .f = mean, before = "3 days") %>%
Expand Down Expand Up @@ -109,14 +109,20 @@ test_that("epi_slide handles classed before/after", {


test_that("epi_slide handles different function specs", {
cfun <- r %>%
step_epi_slide(value, .f = "mean", before = 3L) %>%
prep(edf) %>%
bake(new_data = NULL)
ffun <- r %>%
step_epi_slide(value, .f = mean, before = 3L) %>%
prep(edf) %>%
bake(new_data = NULL)
expect_warning(
cfun <- r %>%
step_epi_slide(value, .f = "mean", before = 3L) %>%
prep(edf) %>%
bake(new_data = NULL),
regexp = "There is an optimized version"
)
expect_warning(
ffun <- r %>%
step_epi_slide(value, .f = mean, before = 3L) %>%
prep(edf) %>%
bake(new_data = NULL),
regexp = "There is an optimized version"
)
# formula NOT currently supported
expect_error(
lfun <- r %>%
Expand All @@ -135,7 +141,7 @@ test_that("epi_slide handles different function specs", {

expect_equal(cfun[[4]], rolled_before)
expect_equal(ffun[[4]], rolled_before)
#expect_equal(lfun[[4]], rolled_before)
# expect_equal(lfun[[4]], rolled_before)
expect_equal(blfun[[4]], rolled_before)
expect_equal(nblfun[[4]], rolled_before)
})

0 comments on commit acc40bd

Please sign in to comment.