Skip to content

Commit 9127952

Browse files
committed
Style and fix&improve some .new_col_name validation
1 parent 8838c71 commit 9127952

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

R/grouped_epi_archive.R

+13-2
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,19 @@ epix_slide.grouped_epi_archive <- function(
284284
validate_slide_window_arg(.before, .x$private$ungrouped$time_type)
285285

286286
checkmate::assert_string(.new_col_name, null.ok = TRUE)
287-
if (identical(.new_col_name, "time_value")) {
288-
cli_abort('`.new_col_name` must not be `"version"`; `epix_slide()` uses that column name to attach which of the `.versions` is associated with each slide computation') # nolint: line_length_linter
287+
if (!is.null(.new_col_name)) {
288+
if (.new_col_name %in% x$private$vars) {
289+
cli_abort(c("`new_col_name` must not be one of the grouping column name(s);
290+
`epix_slide()` uses these column name(s) to label what group
291+
each slide computation came from.",
292+
"i" = "{cli::qty(length(x$private$vars))} grouping column name{?s}
293+
{?was/were} {format_chr_with_quotes(x$private$vars)}",
294+
"x" = "`new_col_name` was {format_chr_with_quotes(new_col_name)}"
295+
))
296+
}
297+
if (identical(.new_col_name, "version")) {
298+
cli_abort('`.new_col_name` must not be `"version"`; `epix_slide()` uses that column name to attach the element of `.versions` associated with each slide computation') # nolint: line_length_linter
299+
}
289300
}
290301

291302
assert_logical(.all_versions, len = 1L)

R/slide.R

+6-5
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,16 @@ epi_slide <- function(
174174
checkmate::assert_string(new_col_name, null.ok = TRUE)
175175
if (!is.null(new_col_name)) {
176176
if (new_col_name %in% group_vars(x)) {
177-
cli_abort(c("`new_col_name` must not be one of the grouping column name(s);
177+
cli_abort(c("`.new_col_name` must not be one of the grouping column name(s);
178178
`epi_slide()` uses these column name(s) to label what group
179179
each slide computation came from.",
180-
"i" = "{cli::qty(length(group_vars(x)))} grouping column name{?s}
181-
{?was/were} {format_chr_with_quotes(group_vars(x))}",
182-
"x" = "`new_col_name` was {format_chr_with_quotes(new_col_name)}"))
180+
"i" = "{cli::qty(length(group_vars(.x)))} grouping column name{?s}
181+
{?was/were} {format_chr_with_quotes(group_vars(.x))}",
182+
"x" = "`.new_col_name` was {format_chr_with_quotes(.new_col_name)}"
183+
))
183184
}
184185
if (identical(new_col_name, "time_value")) {
185-
cli_abort('`new_col_name` must not be `"time_value"`; `epi_slide()` uses that column name to attach the `ref_time_value` associated with each slide computation') # nolint: line_length_linter
186+
cli_abort('`.new_col_name` must not be `"time_value"`; `epi_slide()` uses that column name to attach the element of `.ref_time_values` associated with each slide computation') # nolint: line_length_linter
186187
}
187188
}
188189

tests/testthat/test-methods-epi_archive.R

+4-2
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ test_that("epix_truncate_version_after returns the same groups as input grouped_
123123
})
124124

125125
test_that("group_vars works as expected", {
126-
expect_equal(ea2_data %>% as_epi_archive() %>% group_by(geo_value) %>% group_vars(),
127-
"geo_value")
126+
expect_equal(
127+
ea2_data %>% as_epi_archive() %>% group_by(geo_value) %>% group_vars(),
128+
"geo_value"
129+
)
128130
})

0 commit comments

Comments
 (0)