Skip to content

Commit cbe1cb1

Browse files
committed
Address additional lints, CHECK issues
1 parent 5df41cd commit cbe1cb1

8 files changed

+53
-17
lines changed

Diff for: R/archive.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ validate_epi_archive <- function(x) {
382382
#' would be `key(DT)`.
383383
#' @param abs_tol numeric, >=0; absolute tolerance to use on numeric measurement
384384
#' columns when determining whether something can be compactified away; see
385-
#' [`is_locf`]
385+
#' [`vec_approx_equal`]
386386
#'
387387
#' @importFrom data.table is.data.table key
388388
#' @importFrom dplyr arrange filter

Diff for: R/epi_slide_opt_archive.R

+18-5
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@
4040
#' epi_slide_opt_archive_one_epikey("value", f, "data.table", 2L, 0L, "day", "slide_value")
4141
#'
4242
#' @keywords internal
43-
epi_slide_opt_archive_one_epikey <- function(updates, in_colnames, f_dots_baked, f_from_package, before, after, time_type, out_colnames) {
43+
epi_slide_opt_archive_one_epikey <- function(
44+
updates,
45+
in_colnames,
46+
f_dots_baked, f_from_package, before, after, time_type,
47+
out_colnames) {
4448
# TODO check for col name clobbering
4549
unit_step <- unit_time_delta(time_type)
4650
prev_inp_snapshot <- NULL
@@ -61,7 +65,7 @@ epi_slide_opt_archive_one_epikey <- function(updates, in_colnames, f_dots_baked,
6165
# If the input had updates in the range t1..t2, this could produce changes
6266
# in slide outputs in the range t1-after..t2+before, and to compute those
6367
# slide values, we need to look at the input snapshot from
64-
# t1-after-before..t2+before+after.
68+
# t1-after-before..t2+before+after. nolint: commented_code_linter
6569
inp_update_t_min <- min(inp_update$time_value)
6670
inp_update_t_max <- max(inp_update$time_value)
6771
slide_t_min <- inp_update_t_min - (before + after) * unit_step
@@ -78,7 +82,8 @@ epi_slide_opt_archive_one_epikey <- function(updates, in_colnames, f_dots_baked,
7882
if (f_from_package == "data.table") {
7983
for (col_i in seq_along(in_colnames)) {
8084
if (before == Inf) {
81-
slide[[out_colnames[[col_i]]]] <- f_dots_baked(slide[[in_colnames[[col_i]]]], seq_len(slide_nrow), adaptive = TRUE)
85+
slide[[out_colnames[[col_i]]]] <-
86+
f_dots_baked(slide[[in_colnames[[col_i]]]], seq_len(slide_nrow), adaptive = TRUE)
8287
} else {
8388
out_col <- f_dots_baked(slide[[in_colnames[[col_i]]]], before + after + 1L)
8489
if (after != 0L) {
@@ -158,7 +163,10 @@ epi_slide_opt.epi_archive <-
158163
purrr::partial(.f, ...)
159164
}
160165
col_names_quo <- enquo(.col_names)
161-
names_info <- across_ish_names_info(.x$DT, time_type, col_names_quo, .f_info$namer, .window_size, .align, .prefix, .suffix, .new_col_names)
166+
names_info <- across_ish_names_info(
167+
.x$DT, time_type, col_names_quo, .f_info$namer,
168+
.window_size, .align, .prefix, .suffix, .new_col_names
169+
)
162170
window_args <- get_before_after_from_window(.window_size, .align, time_type)
163171
if (!is.null(.ref_time_values)) {
164172
cli_abort("epi_slide.epi_archive does not support the `.ref_time_values` argument")
@@ -187,7 +195,12 @@ epi_slide_opt.epi_archive <-
187195
nest(.by = version, .key = "subtbl") %>%
188196
arrange(version)
189197
# TODO move nesting inside the helper?
190-
res <- epi_slide_opt_archive_one_epikey(group_updates, names_info$input_col_names, .f_dots_baked, .f_info$from_package, window_args$before, window_args$after, time_type, names_info$output_col_names) %>%
198+
res <- epi_slide_opt_archive_one_epikey(
199+
group_updates,
200+
names_info$input_col_names,
201+
.f_dots_baked, .f_info$from_package, window_args$before, window_args$after, time_type,
202+
names_info$output_col_names
203+
) %>%
191204
list_rbind()
192205
if (use_progress) cli::cli_progress_update(id = progress_bar_id)
193206
res

Diff for: R/epi_slide_opt_edf.R

+8-4
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ upstream_slide_f_info <- function(.f) {
8181
#' `names(.x)`; and `output_colnames`, chr, same length as `input_col_names`
8282
#'
8383
#' @keywords internal
84-
across_ish_names_info <- function(.x, time_type, col_names_quo, .f_namer, .window_size, .align, .prefix, .suffix, .new_col_names) {
84+
across_ish_names_info <- function(.x, time_type, col_names_quo, .f_namer,
85+
.window_size, .align, .prefix, .suffix, .new_col_names) {
8586
# The position of a given column can be differ between input `.x` and
8687
# `.data_group` since the grouping step by default drops grouping columns.
8788
# To avoid rerunning `eval_select` for every `.data_group`, convert
@@ -151,10 +152,10 @@ across_ish_names_info <- function(.x, time_type, col_names_quo, .f_namer, .windo
151152
}
152153
output_col_names <- .new_col_names
153154

154-
return(list(
155+
list(
155156
input_col_names = input_col_names,
156157
output_col_names = output_col_names
157-
))
158+
)
158159
}
159160

160161
#' Optimized slide functions for common cases
@@ -417,7 +418,10 @@ epi_slide_opt.epi_df <- function(.x, .col_names, .f, ...,
417418
window_args <- get_before_after_from_window(.window_size, .align, time_type)
418419

419420
# Handle output naming:
420-
names_info <- across_ish_names_info(.x, time_type, col_names_quo, f_info$namer, .window_size, .align, .prefix, .suffix, .new_col_names)
421+
names_info <- across_ish_names_info(
422+
.x, time_type, col_names_quo, f_info$namer,
423+
.window_size, .align, .prefix, .suffix, .new_col_names
424+
)
421425
input_col_names <- names_info$input_col_names
422426
output_col_names <- names_info$output_col_names
423427

Diff for: R/patch.R

+7-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
#' @param na_equal should `NA`s be considered equal to each other? (In
1313
#' epiprocess, we usually want this to be `TRUE`, but that doesn't match the
1414
#' [`vctrs::vec_equal()`] default, so this is mandatory.)
15+
#' @param .ptype as in [`vctrs::vec_equal()`].
16+
#' @param ... should be empty (it's here to force later arguments to be passed
17+
#' by name)
1518
#' @param abs_tol absolute tolerance; will be used for bare numeric `vec1`,
1619
#' `vec2`, or any such columns within `vec1`, `vec2` if they are data frames.
17-
#' @param .ptype as in [`vctrs::vec_equal()`].
1820
#' @param inds1,inds2 optional (row) indices into vec1 and vec2 compatible with
1921
#' [`vctrs::vec_slice()`]; output should be consistent with `vec_slice`-ing to
2022
#' these indices beforehand, but can give faster computation if `vec1` and
@@ -205,7 +207,9 @@ tbl_diff2 <- function(earlier_snapshot, later_tbl,
205207
cli_abort("`ukey_names` must be a subset of column names")
206208
}
207209
later_format <- arg_match0(later_format, c("snapshot", "update"))
208-
if (!(is.vector(compactify_abs_tol, mode = "numeric") && length(compactify_abs_tol) == 1L && compactify_abs_tol >= 0)) {
210+
if (!(is.vector(compactify_abs_tol, mode = "numeric") &&
211+
length(compactify_abs_tol) == 1L && # nolint:indentation_linter
212+
compactify_abs_tol >= 0)) {
209213
# Give a specific message:
210214
assert_numeric(compactify_abs_tol, lower = 0, any.missing = FALSE, len = 1L)
211215
# Fallback e.g. for invalid classes not caught by assert_numeric:
@@ -279,7 +283,7 @@ tbl_diff2 <- function(earlier_snapshot, later_tbl,
279283
if (later_format == "update") {
280284
# Cases 4. and 5.:
281285
combined_tbl <- combined_tbl[combined_from_later & !combined_compactify_away, ]
282-
} else { # later_format == "snapshot"
286+
} else { # later_format is "snapshot"
283287
# Which rows from combined are in case 1.?
284288
combined_is_deletion <- vec_rep_each(c(TRUE, FALSE), c(earlier_n, later_n))
285289
combined_is_deletion[ukey_repeat_first_i] <- FALSE

Diff for: man/apply_compactify.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: man/vec_approx_equal.Rd

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: tests/testthat/test-archive.R

+9-1
Original file line numberDiff line numberDiff line change
@@ -220,5 +220,13 @@ test_that("`epi_archive` rejects dataframes where time_value and version columns
220220
test_that("is_locf replacement works as expected", {
221221
vec <- c(1, 1, 1e-10, 1.1e-10, NA, NA, NaN, NaN)
222222
is_repeated <- c(0, 1, 0, 1, 0, 1, 1, 1)
223-
expect_equal(c(FALSE, vec_approx_equal(head(vec, -1L), tail(vec, -1L), na_equal = TRUE, abs_tol = .Machine$double.eps^0.5)), as.logical(is_repeated))
223+
expect_equal(
224+
c(
225+
FALSE,
226+
vec_approx_equal(head(vec, -1L), tail(vec, -1L),
227+
na_equal = TRUE, abs_tol = .Machine$double.eps^0.5
228+
)
229+
),
230+
as.logical(is_repeated)
231+
)
224232
})

Diff for: tests/testthat/test-epi_slide_opt_archive.R

+6-2
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ test_that("epi_slide_opt.epi_archive gives expected results on example data; als
159159

160160
mini_case_death_rate_archive_time_gen <- system.time(
161161
mini_case_death_rate_archive_expected <- mini_case_death_rate_archive %>%
162-
epix_slide(~ .x %>% epi_slide_opt(case_rate, frollmean, .window_size = 7)) %>%
162+
epix_slide(
163+
~ .x %>% epi_slide_opt(case_rate, frollmean, .window_size = 7)
164+
) %>%
163165
select(names(mini_case_death_rate_archive$DT), everything()) %>%
164166
as_epi_archive()
165167
)
@@ -205,7 +207,9 @@ test_that("epi_slide_opt.epi_archive gives expected results on example data; als
205207

206208
archive_cases_dv_subset_time_gen <- system.time(
207209
archive_cases_dv_subset_expected <- archive_cases_dv_subset %>%
208-
epix_slide(~ .x %>% epi_slide_opt(percent_cli, frollmean, .window_size = 7)) %>%
210+
epix_slide(
211+
~ .x %>% epi_slide_opt(percent_cli, frollmean, .window_size = 7)
212+
) %>%
209213
select(geo_value, time_value, version, everything()) %>%
210214
as_epi_archive()
211215
)

0 commit comments

Comments
 (0)