From acc40bd25686d7feaf151f659530ec0d3ae03a1d Mon Sep 17 00:00:00 2001 From: dsweber2 Date: Wed, 31 Jul 2024 14:11:44 -0500 Subject: [PATCH] new version passes the tests --- R/step_epi_slide.R | 7 +++---- tests/testthat/test-step_epi_slide.R | 28 +++++++++++++++++----------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/R/step_epi_slide.R b/R/step_epi_slide.R index 64cd5370f..6b766b9d6 100644 --- a/R/step_epi_slide.R +++ b/R/step_epi_slide.R @@ -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" ) } @@ -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, diff --git a/tests/testthat/test-step_epi_slide.R b/tests/testthat/test-step_epi_slide.R index 215fdb43c..1f284b721 100644 --- a/tests/testthat/test-step_epi_slide.R +++ b/tests/testthat/test-step_epi_slide.R @@ -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( @@ -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") %>% @@ -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 %>% @@ -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) })