Skip to content

Commit 2eabcc0

Browse files
committed
Dot-prefix local vars when we never want to use similarly-named arg
Local variables `f`, `starts`, and `stops` are never used at the same time as arguments `.f`, `.starts`, and `.stops`. To prevent accidental usage due to similar naming, dot-prefix the local variables as well. We might later separate out helper functions from being nested functions, and this would avoid such accidents as well; we then may be able to remove some of these dot prefixes if desired.
1 parent 1181b97 commit 2eabcc0

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

R/slide.R

+8-8
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ epi_slide <- function(
191191
.x <- arrange(.x, .data$time_value)
192192

193193
# Now set up starts and stops for sliding/hopping
194-
starts <- .ref_time_values - before
195-
stops <- .ref_time_values + after
194+
.starts <- .ref_time_values - before
195+
.stops <- .ref_time_values + after
196196

197197
# If `.f` is missing, interpret ... as an expression for tidy evaluation
198198
if (missing(.f)) {
@@ -211,7 +211,7 @@ epi_slide <- function(
211211
used_data_masking <- FALSE
212212
}
213213

214-
f <- as_time_slide_computation(.f, ...)
214+
.f <- as_time_slide_computation(.f, ...)
215215

216216
# Create a wrapper that calculates and passes `.ref_time_value` to the
217217
# computation. `i` is contained in the `f_wrapper_factory` environment such
@@ -222,7 +222,7 @@ epi_slide <- function(
222222
f_wrapper <- function(.x, .group_key, ...) {
223223
.ref_time_value <- kept_ref_time_values[[i]]
224224
i <<- i + 1L
225-
f(.x, .group_key, .ref_time_value, ...)
225+
.f(.x, .group_key, .ref_time_value, ...)
226226
}
227227
return(f_wrapper)
228228
}
@@ -246,15 +246,15 @@ epi_slide <- function(
246246
.stops <- .stops[o]
247247
kept_ref_time_values <- .ref_time_values[o]
248248

249-
f <- .f_factory(kept_ref_time_values)
249+
.f <- .f_factory(kept_ref_time_values)
250250

251251
# Compute the slide values
252252
slide_values_list <- slider::hop_index(
253253
.x = .data_group,
254254
.i = .data_group$time_value,
255255
.starts = .starts,
256256
.stops = .stops,
257-
.f = f,
257+
.f = .f,
258258
.group_key, ...
259259
)
260260

@@ -339,8 +339,8 @@ epi_slide <- function(
339339
.x <- group_modify(.x, slide_one_grp,
340340
...,
341341
.f_factory = f_wrapper_factory,
342-
.starts = starts,
343-
.stops = stops,
342+
.starts = .starts,
343+
.stops = .stops,
344344
.ref_time_values = .ref_time_values,
345345
.all_rows = .all_rows,
346346
.new_col_name = .new_col_name,

0 commit comments

Comments
 (0)