Skip to content

Commit 5f588e0

Browse files
committed
fix warn for slide_opt's multi column case
1 parent 62155cc commit 5f588e0

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

R/slide.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#'
4040
#' @importFrom lubridate days weeks
4141
#' @importFrom dplyr bind_rows group_vars filter select
42-
#' @importFrom rlang .data .env !! enquo enquos sym env missing_arg
42+
#' @importFrom rlang .data .env !! enquos sym env missing_arg
4343
#' @export
4444
#' @seealso [`epi_slide_opt`] [`epi_slide_mean`] [`epi_slide_sum`]
4545
#' @examples
@@ -321,7 +321,7 @@ epi_slide <- function(x, f, ..., before = NULL, after = NULL, ref_time_values =
321321
#'
322322
#' @template opt-slide-details
323323
#'
324-
#' @importFrom dplyr bind_rows mutate %>% arrange tibble select
324+
#' @importFrom dplyr bind_rows mutate %>% arrange tibble select all_of
325325
#' @importFrom rlang enquo quo_get_expr as_label expr_label caller_arg
326326
#' @importFrom tidyselect eval_select
327327
#' @importFrom purrr map map_lgl
@@ -495,7 +495,7 @@ epi_slide_opt <- function(x, col_names, f, ..., before = NULL, after = NULL, ref
495495
# positions of user-provided `col_names` into string column names. We avoid
496496
# using `names(pos)` directly for robustness and in case we later want to
497497
# allow users to rename fields via tidyselection.
498-
pos <- eval_select(rlang::enquo(col_names), data = x, allow_rename = FALSE)
498+
pos <- eval_select(all_of(col_names), data = x, allow_rename = FALSE)
499499
col_names_chr <- names(x)[pos]
500500
# Always rename results to "slide_value_<original column name>".
501501
result_col_names <- paste0("slide_value_", col_names_chr)

tests/testthat/test-epi_slide.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,3 +1273,14 @@ test_that("`epi_slide_opt` errors when passed non-`data.table`, non-`slider` fun
12731273
class = "epiprocess__epi_slide_opt__unsupported_slide_function"
12741274
)
12751275
})
1276+
1277+
1278+
multi_columns <- dplyr::bind_rows(
1279+
dplyr::tibble(geo_value = "ak", time_value = test_date + 1:200, value = 1:200, value2 = -1:-200),
1280+
dplyr::tibble(geo_value = "al", time_value = test_date + 1:5, value = -(1:5), value2 = 1:5)
1281+
) %>%
1282+
as_epi_df() %>% group_by(geo_value)
1283+
1284+
test_that("no dplyr warnings from selecting multiple columns", {
1285+
expect_no_warning(epi_slide_mean(multi_columns, col_names = c("value", "value2"), before=3L))
1286+
})

0 commit comments

Comments
 (0)