Skip to content

Commit 4e65e51

Browse files
authored
Merge pull request #436 from cmu-delphi/ndefries/opt-slide-cleanup
Idiomatic cleanup of `epi_slide_opt` computation function checks
2 parents 2e694e5 + fc2590d commit 4e65e51

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ importFrom(rlang,caller_env)
142142
importFrom(rlang,enquo)
143143
importFrom(rlang,enquos)
144144
importFrom(rlang,env)
145+
importFrom(rlang,expr_label)
145146
importFrom(rlang,f_env)
146147
importFrom(rlang,f_rhs)
147148
importFrom(rlang,is_environment)

R/slide.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,8 @@ epi_slide <- function(x, f, ..., before, after, ref_time_values,
376376
#' @template opt-slide-details
377377
#'
378378
#' @importFrom dplyr bind_rows mutate %>% arrange tibble select
379-
#' @importFrom rlang enquo quo_get_expr as_label
380-
#' @importFrom purrr map
379+
#' @importFrom rlang enquo quo_get_expr as_label expr_label caller_arg
380+
#' @importFrom purrr map map_lgl
381381
#' @importFrom data.table frollmean frollsum frollapply
382382
#' @importFrom lubridate as.period
383383
#' @importFrom checkmate assert_function
@@ -459,25 +459,25 @@ epi_slide_opt <- function(x, col_names, f, ..., before, after, ref_time_values,
459459
# `data.table` and `slider` (or a function that has the exact same
460460
# definition, e.g. if the function has been reexported or defined
461461
# locally).
462-
if (any(sapply(
463-
c(frollmean, frollsum, frollapply),
462+
if (any(map_lgl(
463+
list(frollmean, frollsum, frollapply),
464464
function(roll_fn) {
465-
isTRUE(identical(f, roll_fn))
465+
identical(f, roll_fn)
466466
}
467467
))) {
468468
f_from_package <- "data.table"
469-
} else if (any(sapply(
470-
c(slide_sum, slide_prod, slide_mean, slide_min, slide_max, slide_all, slide_any),
469+
} else if (any(map_lgl(
470+
list(slide_sum, slide_prod, slide_mean, slide_min, slide_max, slide_all, slide_any),
471471
function(roll_fn) {
472-
isTRUE(identical(f, roll_fn))
472+
identical(f, roll_fn)
473473
}
474474
))) {
475475
f_from_package <- "slider"
476476
} else {
477477
# `f` is from somewhere else and not supported
478478
cli_abort(
479479
c(
480-
"slide function `f` is not supported",
480+
"problem with {rlang::expr_label(rlang::caller_arg(f))}",
481481
"i" = "`f` must be one of `data.table`'s rolling functions (`frollmean`,
482482
`frollsum`, `frollapply`. See `?data.table::roll`) or one of
483483
`slider`'s specialized sliding functions (`slide_mean`, `slide_sum`,

0 commit comments

Comments
 (0)