Skip to content

Commit eb75dc0

Browse files
committed
epi_slide refactor: remove dots baking, improve error when user double-passes arg
1 parent 1405bbf commit eb75dc0

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,28 +107,20 @@ 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) {
124116
grp_data[, out_colnames] <-
125-
f_dots_baked(grp_data[, in_colnames], seq_len(nrow(grp_data)), adaptive = TRUE)
117+
.f(x = grp_data[, in_colnames], n = seq_len(nrow(grp_data)), adaptive = TRUE, ...)
126118
grp_data[, out_colnames] <- out_cols
127119
grp_data
128120
}
129121
} else {
130122
function(grp_data, grp_key, ref_inds) {
131-
out_cols <- .f(grp_data[, in_colnames], .before_n_steps + .after_n_steps + 1L, ...)
123+
out_cols <- .f(x = grp_data[, in_colnames], n = .before_n_steps + .after_n_steps + 1L, ...)
132124
if (.after_n_steps != 0L) {
133125
# Shift an appropriate amount of NA padding from the start to the end.
134126
# (This padding will later be cut off when we filter down to the
@@ -145,7 +137,7 @@ upstream_slide_to_simple_hop <- function(.f, ..., .in_colnames, .out_colnames, .
145137
function(grp_data, grp_key, ref_inds) {
146138
names(in_colnames) <- in_colnames
147139
lapply(in_colnames, function(in_colname) {
148-
f_dots_baked(grp_data[[in_colname]], before = .before_n_steps, after = .after_n_steps)
140+
.f(x = grp_data[[in_colname]], before = .before_n_steps, after = .after_n_steps, ...)
149141
})
150142
},
151143
# TODO improve message

0 commit comments

Comments
 (0)