Skip to content

Commit 1c379fb

Browse files
committed
works for both character and tidyselect
1 parent f3a844e commit 1c379fb

File tree

8 files changed

+37
-24
lines changed

8 files changed

+37
-24
lines changed

R/slide.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,11 @@ 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(all_of(col_names), data = x, allow_rename = FALSE)
498+
if (typeof(quo_get_expr(enquo(col_names))) == "character") {
499+
pos <- eval_select(all_of(col_names), data = x, allow_rename = FALSE)
500+
} else {
501+
pos <- eval_select(enquo(col_names), data = x, allow_rename = FALSE)
502+
}
499503
col_names_chr <- names(x)[pos]
500504
# Always rename results to "slide_value_<original column name>".
501505
result_col_names <- paste0("slide_value_", col_names_chr)

man-roxygen/opt-slide-params.R

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#' @param col_names <[`tidy-select`][dplyr_tidy_select]> An unquoted column
2-
#' name(e.g., `cases`), multiple column names (e.g., `c(cases, deaths)`), or
3-
#' [other tidy-select expression][tidyselect::language]. Variable names can
4-
#' be used as if they were positions in the data frame, so expressions like
5-
#' `x:y` can be used to select a range of variables. If you have the desired
6-
#' column names stored in a vector `vars`, use `col_names = all_of(vars)`.
2+
#' name(e.g., `cases`), multiple column names (e.g., `c(cases, deaths)`),
3+
#' [other tidy-select expression][tidyselect::language], or a vector of
4+
#' characters (e.g. `c("cases", "deaths")`). Variable names can be used as if
5+
#' they were positions in the data frame, so expressions like `x:y` can be
6+
#' used to select a range of variables. If you have the desired column names
7+
#' stored in a vector `vars`, use `col_names = all_of(vars)`.
78
#'
89
#' The tidy-selection renaming interface is not supported, and cannot be used
910
#' to provide output column names; if you want to customize the output column

man/epi_slide_mean.Rd

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/epi_slide_opt.Rd

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/epi_slide_sum.Rd

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-epi_slide.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1283,5 +1283,10 @@ multi_columns <- dplyr::bind_rows(
12831283
group_by(geo_value)
12841284

12851285
test_that("no dplyr warnings from selecting multiple columns", {
1286-
expect_no_warning(epi_slide_mean(multi_columns, col_names = c("value", "value2"), before = 3L))
1286+
expect_no_warning(multi_slid <- epi_slide_mean(multi_columns, col_names = c("value", "value2"), before = 3L))
1287+
expect_equal(names(multi_slid), c("geo_value", "time_value", "value", "value2", "slide_value_value", "slide_value_value2"))
1288+
expect_no_warning(multi_slid_select <- epi_slide_mean(multi_columns, c(value, value2), before = 3L))
1289+
expect_equal(multi_slid_select, multi_slid)
1290+
expect_no_warning(multi_slid_select <- epi_slide_mean(multi_columns, starts_with("value"), before = 3L))
1291+
expect_equal(multi_slid_select, multi_slid)
12871292
})

tests/testthat/test-epix_slide.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
library(dplyr)
1+
suppressPackageStartupMessages(library(dplyr))
22

33
test_date <- as.Date("2020-01-01")
44

tests/testthat/test-grouped_epi_archive.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
test_that("Grouping, regrouping, and ungrouping archives works as intended", {
22
# From an example:
3-
library(dplyr)
3+
suppressPackageStartupMessages(library(dplyr))
44
toy_archive <-
55
tribble(
66
~geo_value, ~age_group, ~time_value, ~version, ~value,

0 commit comments

Comments
 (0)