Skip to content

Commit 496178a

Browse files
committed
accessing wrong object, renaming x, fixed snapshot
1 parent 68f8c50 commit 496178a

File tree

3 files changed

+33
-32
lines changed

3 files changed

+33
-32
lines changed

R/revision_analysis.R

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -222,56 +222,57 @@ revision_analysis <- function(epi_arch,
222222
}
223223

224224
#' @export
225-
print.revision_behavior <- function(x, ...) {
226-
cli::cli_h2("An epi_archive spanning {.val {x$range_time_values[1]}} to {.val {x$range_time_values[1]}}.")
225+
print.revision_behavior <- function(rev_beh, ...) {
226+
revision_behavior <- rev_beh$revision_behavior
227+
cli::cli_h2("An epi_archive spanning {.val {rev_beh$range_time_values[1]}} to {.val {rev_beh$range_time_values[1]}}.")
227228
cli::cli_h3("Min lag (time to first version):")
228-
time_delta_summary(x$revision_behavior$min_lag, x$time_type) %>% print()
229-
if (!x$drop_nas) {
229+
time_delta_summary(revision_behavior$min_lag, rev_beh$time_type) %>% print()
230+
if (!rev_beh$drop_nas) {
230231
cli_inform("Fraction of all versions that are `NA`:")
231-
cli_li(num_percent(x$total_na, x$n_obs, ""))
232+
cli_li(num_percent(rev_beh$total_na, rev_beh$n_obs, ""))
232233
cli_inform("")
233234
}
234235
cli::cli_h3("Fraction of epi_key + time_values with")
235-
total_num <- nrow(x$revision_behavior) # nolint: object_usage_linter
236-
total_num_unrevised <- sum(x$n_revisions == 0) # nolint: object_usage_linter
236+
total_num <- nrow(revision_behavior) # nolint: object_usage_linter
237+
total_num_unrevised <- sum(revision_behavior$n_revisions == 0) # nolint: object_usage_linter
237238
cli_inform("No revisions:")
238239
cli_li(num_percent(total_num_unrevised, total_num, ""))
239240
total_quickly_revised <- sum( # nolint: object_usage_linter
240-
time_delta_to_n_steps(x$revision_behavior$max_lag, x$time_type) <=
241-
time_delta_to_n_steps(x$quick_revision, x$time_type)
241+
time_delta_to_n_steps(revision_behavior$max_lag, rev_beh$time_type) <=
242+
time_delta_to_n_steps(rev_beh$quick_revision, rev_beh$time_type)
242243
)
243-
cli_inform("Quick revisions (last revision within {format_time_delta(x$quick_revision, x$time_type)}
244+
cli_inform("Quick revisions (last revision within {format_time_delta(rev_beh$quick_revision, rev_beh$time_type)}
244245
of the `time_value`):")
245246
cli_li(num_percent(total_quickly_revised, total_num, ""))
246247
total_barely_revised <- sum( # nolint: object_usage_linter
247-
x$n_revisions <= x$few_revisions
248+
revision_behavior$n_revisions <= rev_beh$few_revisions
248249
)
249-
cli_inform("Few revisions (At most {x$few_revisions} revisions for that `time_value`):")
250+
cli_inform("Few revisions (At most {rev_beh$few_revisions} revisions for that `time_value`):")
250251
cli_li(num_percent(total_barely_revised, total_num, ""))
251252

252253
cli::cli_h3("Fraction of revised epi_key + time_values which have:")
253254

254-
real_revisions <- x$revision_behavior %>% filter(n_revisions > 0) # nolint: object_usage_linter
255+
real_revisions <- revision_behavior %>% filter(n_revisions > 0) # nolint: object_usage_linter
255256
n_real_revised <- nrow(real_revisions) # nolint: object_usage_linter
256257
rel_spread <- sum( # nolint: object_usage_linter
257258
real_revisions$rel_spread <
258-
x$rel_spread_threshold,
259+
rev_beh$rel_spread_threshold,
259260
na.rm = TRUE
260261
) + sum(is.na(real_revisions$rel_spread))
261-
cli_inform("Less than {x$rel_spread_threshold} spread in relative value:")
262+
cli_inform("Less than {rev_beh$rel_spread_threshold} spread in relative value:")
262263
cli_li(num_percent(rel_spread, n_real_revised, ""))
263264
abs_spread <- sum( # nolint: object_usage_linter
264265
real_revisions$spread >
265-
x$abs_spread_threshold
266+
rev_beh$abs_spread_threshold
266267
) # nolint: object_usage_linter
267-
cli_inform("Spread of more than {x$abs_spread_threshold} in actual value (when revised):")
268+
cli_inform("Spread of more than {rev_beh$abs_spread_threshold} in actual value (when revised):")
268269
cli_li(num_percent(abs_spread, n_real_revised, ""))
269270

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

277278
#' @export

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)