Skip to content

Commit 32403fb

Browse files
committed
rebuild docs and test
1 parent 4c67630 commit 32403fb

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

R/revision_analysis.R

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,6 @@ revision_analysis <- function(epi_arch,
113113
cli_abort("Not currently implementing more than one column at a time. Run each separately.")
114114
}
115115
}
116-
if (is.null(abs_spread_threshold)) {
117-
abs_spread_threshold <- .05 * epi_arch$DT %>%
118-
pull(!!arg) %>%
119-
max(na.rm = TRUE)
120-
}
121116
# for each time_value, get
122117
# the number of revisions
123118
# the maximum spread in value (both absolute and relative)
@@ -191,6 +186,7 @@ revision_analysis <- function(epi_arch,
191186
drop_nas = drop_nas,
192187
time_type = time_type,
193188
total_na = total_na,
189+
max_val = max(epi_arch$DT[[arg]], na.rm = TRUE),
194190
n_obs = nrow(epi_arch$DT),
195191
within_latest = within_latest
196192
), class = "revision_analysis")
@@ -227,8 +223,9 @@ print.revision_analysis <- function(x,
227223
abs_spread_threshold = NULL,
228224
rel_spread_threshold = 0.1,
229225
...) {
226+
if (is.null(abs_spread_threshold)) abs_spread_threshold <- .05 * x$max_val
230227
rev_beh <- x$revision_behavior
231-
cli::cli_h2("An epi_archive spanning {.val {rev_beh$range_time_values[1]}} to {.val {rev_beh$range_time_values[1]}}.")
228+
cli::cli_h2("An epi_archive spanning {.val {x$range_time_values[1]}} to {.val {x$range_time_values[1]}}.")
232229
cli::cli_h3("Min lag (time to first version):")
233230
time_delta_summary(rev_beh$min_lag, x$time_type) %>% print()
234231
if (!x$drop_nas) {
@@ -248,8 +245,8 @@ print.revision_analysis <- function(x,
248245
cli_inform("Quick revisions (last revision within {format_time_delta(quick_revision, x$time_type)}
249246
of the `time_value`):")
250247
cli_li(num_percent(total_quickly_revised, total_num, ""))
251-
total_barely_revised <- sum(x$n_revisions <= few_revisions)
252-
cli_inform("Few revisions (At most {few_revisions} revisions for that `time_value`):")
248+
total_barely_revised <- sum(rev_beh$n_revisions <= few_revisions)
249+
cli_inform("Few revisions (At most {.val {few_revisions}} revisions for that `time_value`):")
253250
cli_li(num_percent(total_barely_revised, total_num, ""))
254251

255252
cli::cli_h3("Fraction of revised epi_key + time_values which have:")
@@ -260,18 +257,20 @@ print.revision_analysis <- function(x,
260257
real_revisions$rel_spread < rel_spread_threshold,
261258
na.rm = TRUE
262259
) + sum(is.na(real_revisions$rel_spread))
263-
cli_inform("Less than {rel_spread_threshold} spread in relative value:")
260+
cli_inform("Less than {.val {rel_spread_threshold}} spread in relative value:")
264261
cli_li(num_percent(rel_spread, n_real_revised, ""))
265262
abs_spread <- sum( # nolint: object_usage_linter
266263
real_revisions$spread > abs_spread_threshold
267264
) # nolint: object_usage_linter
268-
cli_inform("Spread of more than {abs_spread_threshold} in actual value (when revised):")
265+
divid <- cli::cli_div(theme = list(.val = list(digits = 3)))
266+
cli_inform("Spread of more than {.val {abs_spread_threshold}} in actual value (when revised):")
267+
cli::cli_end(divid)
269268
cli_li(num_percent(abs_spread, n_real_revised, ""))
270269

271270
# time_type_unit_pluralizer[[time_type]] is a format string controlled by us
272271
# and/or downstream devs, so we can paste it onto our format string safely:
273272
units_plural <- pluralize(paste0("{qty(2)}", time_type_unit_pluralizer[[x$time_type]])) # nolint: object_usage_linter
274-
cli::cli_h3("{toTitleCase(units_plural)} until within {x$within_latest*100}% of the latest value:")
273+
cli::cli_h3("{toTitleCase(units_plural)} until within {.val {x$within_latest*100}}% of the latest value:")
275274
time_delta_summary(rev_beh[["lag_near_latest"]], x$time_type) %>% print()
276275
}
277276

tests/testthat/_snaps/revision-latency-functions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@
239239
---
240240

241241
Code
242-
rs5
242+
print(rs5, quick_revision = 3)
243243
Message
244244
245245
-- An epi_archive spanning 1 to 1. --

tests/testthat/test-revision-latency-functions.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ test_that("revision_summary works for dummy datasets", {
8989
# something nonsensical, but we tried.
9090
rs5 <- dummy_ex_integerly %>%
9191
revision_summary(
92-
min_waiting_period = 60, quick_revision = 3,
92+
min_waiting_period = 60,
9393
drop_nas = FALSE
9494
)
95-
expect_snapshot(rs5)
95+
expect_snapshot(print(rs5, quick_revision = 3))
9696
expect_snapshot(rs5$revision_behavior %>% print(n = 10, width = 300))
9797
})
9898

0 commit comments

Comments
 (0)