Skip to content

Commit 8df28e3

Browse files
committed
style
1 parent 9a62deb commit 8df28e3

File tree

1 file changed

+48
-48
lines changed

1 file changed

+48
-48
lines changed

R/slide.R

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -332,63 +332,63 @@ epi_slide <- function(
332332
}
333333

334334
# TODO refactor this out and use it in epix_slide as well if possible
335-
if (is.null(.new_col_name)) {
336-
if (inherits(slide_values, "data.frame")) {
337-
# Sometimes slide_values can parrot back columns already in `res`; allow
338-
# this, but balk if a column has the same name as one in `res` but a
339-
# different value:
340-
comp_nms <- names(slide_values)
341-
overlaps_existing_names <- comp_nms %in% names(res)
342-
for (comp_i in which(overlaps_existing_names)) {
343-
if (!identical(slide_values[[comp_i]], res[[comp_nms[[comp_i]]]])) {
344-
lines <- c(
345-
cli::format_error(c(
346-
"New column and old column clash",
347-
"x" = "slide computation output included a
335+
if (is.null(.new_col_name)) {
336+
if (inherits(slide_values, "data.frame")) {
337+
# Sometimes slide_values can parrot back columns already in `res`; allow
338+
# this, but balk if a column has the same name as one in `res` but a
339+
# different value:
340+
comp_nms <- names(slide_values)
341+
overlaps_existing_names <- comp_nms %in% names(res)
342+
for (comp_i in which(overlaps_existing_names)) {
343+
if (!identical(slide_values[[comp_i]], res[[comp_nms[[comp_i]]]])) {
344+
lines <- c(
345+
cli::format_error(c(
346+
"New column and old column clash",
347+
"x" = "slide computation output included a
348348
{format_varname(comp_nms[[comp_i]])} column, but `.x` already had a
349349
{format_varname(comp_nms[[comp_i]])} column with differing values",
350-
"Here are examples of differing values, where the grouping variables were
350+
"Here are examples of differing values, where the grouping variables were
351351
{format_tibble_row(.group_key)}:"
352-
)),
353-
capture.output(print(waldo::compare(
354-
res[[comp_nms[[comp_i]]]], slide_values[[comp_i]],
355-
x_arg = rlang::expr_deparse(dplyr::expr(`$`(!!"existing", !!sym(comp_nms[[comp_i]])))), # nolint: object_usage_linter
356-
y_arg = rlang::expr_deparse(dplyr::expr(`$`(!!"comp_value", !!sym(comp_nms[[comp_i]])))) # nolint: object_usage_linter
357-
))),
358-
cli::format_message(c(
359-
">" = "You likely want to rename or remove this column from your slide
352+
)),
353+
capture.output(print(waldo::compare(
354+
res[[comp_nms[[comp_i]]]], slide_values[[comp_i]],
355+
x_arg = rlang::expr_deparse(dplyr::expr(`$`(!!"existing", !!sym(comp_nms[[comp_i]])))), # nolint: object_usage_linter
356+
y_arg = rlang::expr_deparse(dplyr::expr(`$`(!!"comp_value", !!sym(comp_nms[[comp_i]])))) # nolint: object_usage_linter
357+
))),
358+
cli::format_message(c(
359+
">" = "You likely want to rename or remove this column from your slide
360360
computation's output, or debug why it has a different value."
361+
))
362+
)
363+
rlang::abort(paste(collapse = "\n", lines),
364+
class = "epiprocess__epi_slide_output_vs_existing_column_conflict"
365+
)
366+
}
367+
}
368+
# Unpack into separate columns (without name prefix). If there are
369+
# columns duplicating existing columns, de-dupe and order them as if they
370+
# didn't exist in slide_values.
371+
res <- dplyr::bind_cols(res, slide_values[!overlaps_existing_names])
372+
} else {
373+
# Apply default name (to vector or packed data.frame-type column):
374+
if ("slide_value" %in% names(res)) {
375+
cli_abort(c("Cannot guess a good column name for your output",
376+
"x" = "`slide_value` already exists in `.x`",
377+
">" = "Please provide a `.new_col_name`."
361378
))
362-
)
363-
rlang::abort(paste(collapse = "\n", lines),
364-
class = "epiprocess__epi_slide_output_vs_existing_column_conflict"
365-
)
379+
}
380+
res[["slide_value"]] <- slide_values
366381
}
382+
} else {
383+
# Vector or packed data.frame-type column (note: overlaps with existing
384+
# column names should already be forbidden by earlier validation):
385+
res[[.new_col_name]] <- slide_values
367386
}
368-
# Unpack into separate columns (without name prefix). If there are
369-
# columns duplicating existing columns, de-dupe and order them as if they
370-
# didn't exist in slide_values.
371-
res <- dplyr::bind_cols(res, slide_values[!overlaps_existing_names])
372-
} else {
373-
# Apply default name (to vector or packed data.frame-type column):
374-
if ("slide_value" %in% names(res)) {
375-
cli_abort(c("Cannot guess a good column name for your output",
376-
"x" = "`slide_value` already exists in `.x`",
377-
">" = "Please provide a `.new_col_name`."
378-
))
379-
}
380-
res[["slide_value"]] <- slide_values
381-
}
382-
} else {
383-
# Vector or packed data.frame-type column (note: overlaps with existing
384-
# column names should already be forbidden by earlier validation):
385-
res[[.new_col_name]] <- slide_values
386-
}
387387
res
388388
}) %>%
389-
list_rbind() %>%
390-
arrange_col_canonical() %>% # XXX is this desired?
391-
group_by(!!!.x_orig_groups)
389+
list_rbind() %>%
390+
arrange_col_canonical() %>% # XXX is this desired?
391+
group_by(!!!.x_orig_groups)
392392

393393
# If every group in epi_slide_one_group takes the
394394
# length(available_ref_time_values) == 0 branch then we end up here.

0 commit comments

Comments
 (0)