diff --git a/R/slide.R b/R/slide.R index 052e3457..158fc690 100644 --- a/R/slide.R +++ b/R/slide.R @@ -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_". + 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)] @@ -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) { @@ -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)) { diff --git a/man-roxygen/opt-slide-params.R b/man-roxygen/opt-slide-params.R index a7d5b04a..6c1ad99d 100644 --- a/man-roxygen/opt-slide-params.R +++ b/man-roxygen/opt-slide-params.R @@ -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 diff --git a/man/epi_slide_mean.Rd b/man/epi_slide_mean.Rd index ee3e7838..adb294bc 100644 --- a/man/epi_slide_mean.Rd +++ b/man/epi_slide_mean.Rd @@ -23,8 +23,12 @@ epi_slide_mean( or ungrouped. If ungrouped, all data in \code{x} will be treated as part of a single data group.} -\item{col_names}{A single tidyselection or a tidyselection vector of the -names of one or more columns for which to calculate the rolling mean.} +\item{col_names}{A <\code{\link[=dplyr_tidy_select]{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 \code{x:y} can +be used to select a range of variables. The tidyselection cannot be used +to provide output column names.} \item{...}{Additional arguments to pass to \code{data.table::frollmean}, for example, \code{na.rm} and \code{algo}. \code{data.table::frollmean} is automatically diff --git a/man/epi_slide_opt.Rd b/man/epi_slide_opt.Rd index 0772b431..dda2adde 100644 --- a/man/epi_slide_opt.Rd +++ b/man/epi_slide_opt.Rd @@ -13,9 +13,9 @@ epi_slide_opt( after, ref_time_values, time_step, - new_col_name = "slide_value", + new_col_name = NULL, as_list_col = NULL, - names_sep = "_", + names_sep = NULL, all_rows = FALSE ) } @@ -24,8 +24,12 @@ epi_slide_opt( or ungrouped. If ungrouped, all data in \code{x} will be treated as part of a single data group.} -\item{col_names}{A single tidyselection or a tidyselection vector of the -names of one or more columns for which to calculate the rolling mean.} +\item{col_names}{A <\code{\link[=dplyr_tidy_select]{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 \code{x:y} can +be used to select a range of variables. The tidyselection cannot be used +to provide output column names.} \item{f}{Function; together with \code{...} specifies the computation to slide. \code{f} must be one of \code{data.table}'s rolling functions diff --git a/man/epi_slide_sum.Rd b/man/epi_slide_sum.Rd index d5961f27..a56c4c72 100644 --- a/man/epi_slide_sum.Rd +++ b/man/epi_slide_sum.Rd @@ -23,8 +23,12 @@ epi_slide_sum( or ungrouped. If ungrouped, all data in \code{x} will be treated as part of a single data group.} -\item{col_names}{A single tidyselection or a tidyselection vector of the -names of one or more columns for which to calculate the rolling mean.} +\item{col_names}{A <\code{\link[=dplyr_tidy_select]{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 \code{x:y} can +be used to select a range of variables. The tidyselection cannot be used +to provide output column names.} \item{...}{Additional arguments to pass to \code{data.table::frollsum}, for example, \code{na.rm} and \code{algo}. \code{data.table::frollsum} is automatically