Skip to content

Commit 0e88ade

Browse files
committed
epi_slide refactor: remove dots baking, improve error when user double-passes arg
1 parent f2e3fb3 commit 0e88ade

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

R/slide-refactor.R

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,25 +107,17 @@ upstream_slide_to_simple_hop <- function(.f, ..., .in_colnames, .out_colnames, .
107107
in_colnames <- .in_colnames
108108
out_colnames <- .out_colnames
109109
f_from_package <- f_info$from_package
110-
f_dots_baked <-
111-
if (rlang::dots_n(...) == 0L) {
112-
# Leaving `.f` unchanged slightly improves computation speed and trims
113-
# debug stack traces:
114-
.f
115-
} else {
116-
purrr::partial(.f, ... = , ...) # `... =` stands in for future args
117-
}
118110
switch(f_from_package,
119111
data.table = if (.before_n_steps == Inf) {
120112
if (.after_n_steps != 0L) {
121113
stop(".before_n_steps only supported with .after_n_steps = 0")
122114
}
123115
function(grp_data, grp_key, ref_inds) {
124-
f_dots_baked(grp_data[, in_colnames], seq_len(nrow(grp_data)), adaptive = TRUE)
116+
.f(x = grp_data[, in_colnames], n = seq_len(nrow(grp_data)), adaptive = TRUE, ...)
125117
}
126118
} else {
127119
function(grp_data, grp_key, ref_inds) {
128-
out_cols <- .f(grp_data[, in_colnames], .before_n_steps + .after_n_steps + 1L, ...)
120+
out_cols <- .f(x = grp_data[, in_colnames], n = .before_n_steps + .after_n_steps + 1L, ...)
129121
if (.after_n_steps != 0L) {
130122
# Shift an appropriate amount of NA padding from the start to the end.
131123
# (This padding will later be cut off when we filter down to the
@@ -142,7 +134,7 @@ upstream_slide_to_simple_hop <- function(.f, ..., .in_colnames, .out_colnames, .
142134
function(grp_data, grp_key, ref_inds) {
143135
names(in_colnames) <- in_colnames
144136
lapply(in_colnames, function(in_colname) {
145-
f_dots_baked(grp_data[[in_colname]], before = .before_n_steps, after = .after_n_steps)
137+
.f(x = grp_data[[in_colname]], before = .before_n_steps, after = .after_n_steps, ...)
146138
})
147139
},
148140
# TODO improve message

0 commit comments

Comments
 (0)