Skip to content

Commit

Permalink
tidyselect can't be used to provide column names
Browse files Browse the repository at this point in the history
  • Loading branch information
nmdefries committed May 29, 2024
1 parent a39a53d commit 0636d25
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
8 changes: 5 additions & 3 deletions R/slide.R
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,8 @@ epi_slide_opt <- function(x, col_names, f, ..., before, after, ref_time_values,
window_size <- before + after + 1L

pos <- eval_select(rlang::enquo(col_names), data = x)
result_col_names <- names(pos)
# Always rename results to "slide_value_<original column name>".
result_col_names <- paste0("slide_value_", names(x[, pos]))
slide_one_grp <- function(.data_group, .group_key, ...) {
missing_times <- all_dates[!(all_dates %in% .data_group$time_value)]

Expand Down Expand Up @@ -605,8 +606,7 @@ epi_slide_opt <- function(x, col_names, f, ..., before, after, ref_time_values,

if (f_from_package == "data.table") {
roll_output <- f(
x = rlang::set_names(.data_group[, pos], result_col_names),
n = window_size, align = "right", ...
x = .data_group[, pos], n = window_size, align = "right", ...
)

if (after >= 1) {
Expand All @@ -616,6 +616,8 @@ epi_slide_opt <- function(x, col_names, f, ..., before, after, ref_time_values,
.data_group[, result_col_names] <- purrr::map(roll_output, function(.x) {
c(.x[(after + 1L):length(.x)], rep(NA, after))
})
} else {
.data_group[, result_col_names] <- roll_output
}
} else if (f_from_package == "slider") {
for (i in seq_along(pos)) {
Expand Down
8 changes: 6 additions & 2 deletions man-roxygen/opt-slide-params.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#' @param col_names A single tidyselection or a tidyselection vector of the
#' names of one or more columns for which to calculate the rolling mean.
#' @param col_names A <[`tidy-select`][dplyr_tidy_select]> of the names of one
#' or more columns for which to calculate a rolling computation. One or more
#' unquoted expressions separated by commas. Variable names can be used as
#' if they were positions in the data frame, so expressions like `x:y` can
#' be used to select a range of variables. The tidyselection cannot be used
#' to provide output column names.
#' @param as_list_col Not supported. Included to match `epi_slide` interface.
#' @param new_col_name Character vector indicating the name(s) of the new
#' column(s) that will contain the derivative values. Default
Expand Down
8 changes: 6 additions & 2 deletions man/epi_slide_mean.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions man/epi_slide_opt.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions man/epi_slide_sum.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0636d25

Please sign in to comment.