Skip to content

Commit 4c67630

Browse files
committed
merge remote
Merge branch 'revision-summary-printing' of https://github.com/cmu-delphi/epiprocess into revision-summary-printing # Conflicts: # R/revision_analysis.R
2 parents 48aa65e + 1592fd8 commit 4c67630

File tree

5 files changed

+57
-56
lines changed

5 files changed

+57
-56
lines changed

NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ S3method(print,epi_archive)
5353
S3method(print,epi_df)
5454
S3method(print,grouped_epi_archive)
5555
S3method(print,growth_rate_params)
56-
S3method(print,revision_behavior)
56+
S3method(print,revision_analysis)
5757
S3method(summary,epi_df)
5858
S3method(ungroup,epi_df)
5959
S3method(ungroup,grouped_epi_archive)

R/revision_analysis.R

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@
6161
#' Using a `time_type` of `"integer"` with week numbers like 202501 will
6262
#' produce incorrect results for some calculations, since week numbering
6363
#' contains jumps at year boundaries.
64-
#'
64+
#'
6565
#' @return An S3 object with class `revision_behavior`. This function is typically
6666
#' called for the purposes of inspecting the printed output. The
67-
#' results of the computations are available in
67+
#' results of the computations are available in
6868
#' `revision_analysis(...)$revision_behavior`. If you only want to access
6969
#' the internal computations, use `return_only_tibble = TRUE`.
7070
#'
@@ -186,7 +186,7 @@ revision_analysis <- function(epi_arch,
186186
if (!return_only_tibble) {
187187
revision_behavior <- structure(list(
188188
revision_behavior = revision_behavior,
189-
range_time_values = range(epi_arch$DT$time_value),
189+
range_time_values = range(epi_arch$DT$time_value),
190190
signal_variable = arg,
191191
drop_nas = drop_nas,
192192
time_type = time_type,
@@ -227,35 +227,34 @@ print.revision_analysis <- function(x,
227227
abs_spread_threshold = NULL,
228228
rel_spread_threshold = 0.1,
229229
...) {
230-
cli::cli_h2("An epi_archive spanning {.val {x$range_time_values[1]}} to {.val {x$range_time_values[1]}}.")
230+
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]}}.")
231232
cli::cli_h3("Min lag (time to first version):")
232-
time_delta_summary(x$revision_behavior$min_lag, x$time_type) %>% print()
233+
time_delta_summary(rev_beh$min_lag, x$time_type) %>% print()
233234
if (!x$drop_nas) {
234235
cli_inform("Fraction of all versions that are `NA`:")
235236
cli_li(num_percent(x$total_na, x$n_obs, ""))
236237
cli_inform("")
237238
}
238239
cli::cli_h3("Fraction of epi_key + time_values with")
239-
total_num <- nrow(x$revision_behavior) # nolint: object_usage_linter
240-
total_num_unrevised <- sum(x$n_revisions == 0) # nolint: object_usage_linter
240+
total_num <- nrow(rev_beh) # nolint: object_usage_linter
241+
total_num_unrevised <- sum(rev_beh$n_revisions == 0) # nolint: object_usage_linter
241242
cli_inform("No revisions:")
242243
cli_li(num_percent(total_num_unrevised, total_num, ""))
243244
total_quickly_revised <- sum( # nolint: object_usage_linter
244-
time_delta_to_n_steps(x$revision_behavior$max_lag, x$time_type) <=
245+
time_delta_to_n_steps(rev_beh$max_lag, x$time_type) <=
245246
time_delta_to_n_steps(quick_revision, x$time_type)
246247
)
247248
cli_inform("Quick revisions (last revision within {format_time_delta(quick_revision, x$time_type)}
248249
of the `time_value`):")
249250
cli_li(num_percent(total_quickly_revised, total_num, ""))
250-
total_barely_revised <- sum( # nolint: object_usage_linter
251-
x$n_revisions <= few_revisions
252-
)
251+
total_barely_revised <- sum(x$n_revisions <= few_revisions)
253252
cli_inform("Few revisions (At most {few_revisions} revisions for that `time_value`):")
254253
cli_li(num_percent(total_barely_revised, total_num, ""))
255-
254+
256255
cli::cli_h3("Fraction of revised epi_key + time_values which have:")
257-
258-
real_revisions <- x$revision_behavior %>% filter(n_revisions > 0) # nolint: object_usage_linter
256+
257+
real_revisions <- rev_beh %>% filter(n_revisions > 0) # nolint: object_usage_linter
259258
n_real_revised <- nrow(real_revisions) # nolint: object_usage_linter
260259
rel_spread <- sum( # nolint: object_usage_linter
261260
real_revisions$rel_spread < rel_spread_threshold,
@@ -268,12 +267,12 @@ print.revision_analysis <- function(x,
268267
) # nolint: object_usage_linter
269268
cli_inform("Spread of more than {abs_spread_threshold} in actual value (when revised):")
270269
cli_li(num_percent(abs_spread, n_real_revised, ""))
271-
270+
272271
# time_type_unit_pluralizer[[time_type]] is a format string controlled by us
273272
# and/or downstream devs, so we can paste it onto our format string safely:
274273
units_plural <- pluralize(paste0("{qty(2)}", time_type_unit_pluralizer[[x$time_type]])) # nolint: object_usage_linter
275274
cli::cli_h3("{toTitleCase(units_plural)} until within {x$within_latest*100}% of the latest value:")
276-
time_delta_summary(x$revision_behavior[["lag_near_latest"]], x$time_type) %>% print()
275+
time_delta_summary(rev_beh[["lag_near_latest"]], x$time_type) %>% print()
277276
}
278277

279278
#' @export

man/revision_analysis.Rd

Lines changed: 29 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
1515
-- Fraction of epi_key + time_values with
1616
No revisions:
17-
* 0 out of 7 (0%)
17+
* 3 out of 7 (42.86%)
1818
Quick revisions (last revision within 3 days of the `time_value`):
1919
* 4 out of 7 (57.14%)
2020
Few revisions (At most 3 revisions for that `time_value`):
21-
* 0 out of 7 (0%)
21+
* 6 out of 7 (85.71%)
2222
2323
-- Fraction of revised epi_key + time_values which have:
2424
Less than 0.1 spread in relative value:
@@ -74,11 +74,11 @@
7474
7575
-- Fraction of epi_key + time_values with
7676
No revisions:
77-
* 0 out of 7 (0%)
77+
* 2 out of 7 (28.57%)
7878
Quick revisions (last revision within 3 days of the `time_value`):
7979
* 4 out of 7 (57.14%)
8080
Few revisions (At most 3 revisions for that `time_value`):
81-
* 0 out of 7 (0%)
81+
* 6 out of 7 (85.71%)
8282
8383
-- Fraction of revised epi_key + time_values which have:
8484
Less than 0.1 spread in relative value:
@@ -134,11 +134,11 @@
134134
135135
-- Fraction of epi_key + time_values with
136136
No revisions:
137-
* 0 out of 7 (0%)
137+
* 2 out of 7 (28.57%)
138138
Quick revisions (last revision within 1 week of the `time_value`):
139139
* 2 out of 7 (28.57%)
140140
Few revisions (At most 3 revisions for that `time_value`):
141-
* 0 out of 7 (0%)
141+
* 6 out of 7 (85.71%)
142142
143143
-- Fraction of revised epi_key + time_values which have:
144144
Less than 0.1 spread in relative value:
@@ -194,11 +194,11 @@
194194
195195
-- Fraction of epi_key + time_values with
196196
No revisions:
197-
* 0 out of 7 (0%)
197+
* 2 out of 7 (28.57%)
198198
Quick revisions (last revision within 1 month of the `time_value`):
199199
* 2 out of 7 (28.57%)
200200
Few revisions (At most 3 revisions for that `time_value`):
201-
* 0 out of 7 (0%)
201+
* 6 out of 7 (85.71%)
202202
203203
-- Fraction of revised epi_key + time_values which have:
204204
Less than 0.1 spread in relative value:
@@ -254,11 +254,11 @@
254254
255255
-- Fraction of epi_key + time_values with
256256
No revisions:
257-
* 0 out of 7 (0%)
257+
* 2 out of 7 (28.57%)
258258
Quick revisions (last revision within 3 time steps of the `time_value`):
259259
* 4 out of 7 (57.14%)
260260
Few revisions (At most 3 revisions for that `time_value`):
261-
* 0 out of 7 (0%)
261+
* 6 out of 7 (85.71%)
262262
263263
-- Fraction of revised epi_key + time_values which have:
264264
Less than 0.1 spread in relative value:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ test_that("revision_summary works for dummy datasets", {
7878
# Yearmonthly has the same story. It would have been close to encountering
7979
# min_waiting_period-based filtering but we actually set its versions_end to
8080
# sometime in 2080 rather than 2022:
81-
rs4 <- dummy_ex_yearmonthly %>% revision_summary(drop_nas = FALSE)
81+
rs4 <- dummy_ex_yearmonthly %>% revision_summary(drop_nas = FALSE)
8282
expect_snapshot(rs4)
8383
expect_snapshot(rs4$revision_behavior %>% print(n = 10, width = 300))
8484
# Integer is very much like daily. We have to provide some of the
@@ -91,7 +91,7 @@ test_that("revision_summary works for dummy datasets", {
9191
revision_summary(
9292
min_waiting_period = 60, quick_revision = 3,
9393
drop_nas = FALSE
94-
)
94+
)
9595
expect_snapshot(rs5)
9696
expect_snapshot(rs5$revision_behavior %>% print(n = 10, width = 300))
9797
})

0 commit comments

Comments
 (0)