4343# ' to `NULL` or 0.
4444# ' @param within_latest double between 0 and 1. Determines the threshold
4545# ' used for the `lag_to`
46- # ' @param quick_revision difftime or integer (integer is treated as days), for
47- # ' the printed summary, the amount of time between the final revision and the
48- # ' actual time_value to consider the revision quickly resolved. Default of 3
49- # ' days
50- # ' @param few_revisions integer, for the printed summary, the upper bound on the
51- # ' number of revisions to consider "few". Default is 3.
52- # ' @param abs_spread_threshold length-1 numeric, for the printed summary, the
53- # ' maximum spread used to characterize revisions which don't actually change
54- # ' very much. Default is 5% of the maximum value in the dataset, but this is
55- # ' the most unit dependent of values, and likely needs to be chosen
56- # ' appropriate for the scale of the dataset.
57- # ' @param rel_spread_threshold length-1 double between 0 and 1, for the printed
58- # ' summary, the relative spread fraction used to characterize revisions which
59- # ' don't actually change very much. Default is .1, or 10% of the final value
6046# ' @param compactify bool. If `TRUE`, we will compactify after the signal
6147# ' requested in `...` has been selected on its own and the `drop_nas` step.
6248# ' This helps, for example, to give similar results when called on
@@ -98,11 +84,6 @@ revision_analysis <- function(epi_arch,
9884 min_waiting_period = as.difftime(60 , units = " days" ) %> %
9985 difftime_approx_ceiling_time_delta(epi_arch $ time_type ),
10086 within_latest = 0.2 ,
101- quick_revision = as.difftime(3 , units = " days" ) %> %
102- difftime_approx_ceiling_time_delta(epi_arch $ time_type ),
103- few_revisions = 3 ,
104- abs_spread_threshold = NULL ,
105- rel_spread_threshold = 0.1 ,
10687 compactify = TRUE ,
10788 compactify_abs_tol = 0 ,
10889 return_only_tibble = FALSE ) {
@@ -211,18 +192,41 @@ revision_analysis <- function(epi_arch,
211192 time_type = time_type ,
212193 total_na = total_na ,
213194 n_obs = nrow(epi_arch $ DT ),
214- quick_revision = quick_revision ,
215- few_revisions = few_revisions ,
216- rel_spread_threshold = rel_spread_threshold ,
217- abs_spread_threshold = abs_spread_threshold ,
218195 within_latest = within_latest
219- ), class = " revision_behavior " )
196+ ), class = " revision_analysis " )
220197 }
221198 return (revision_behavior )
222199}
223200
201+
202+
203+
204+ # ' Print a `revision_analysis` object
205+ # '
206+ # ' @param x a `revision_analysis` object
207+ # ' @param quick_revision Difftime or integer (integer is treated as days).
208+ # ' The amount of time between the final revision and the
209+ # ' actual time_value to consider the revision quickly resolved. Default of 3
210+ # ' days
211+ # ' @param few_revisions Integer. The upper bound on the
212+ # ' number of revisions to consider "few". Default is 3.
213+ # ' @param abs_spread_threshold Scalar numeric. The
214+ # ' maximum spread used to characterize revisions which don't actually change
215+ # ' very much. Default is 5% of the maximum value in the dataset, but this is
216+ # ' the most unit dependent of values, and likely needs to be chosen
217+ # ' appropriate for the scale of the dataset.
218+ # ' @param rel_spread_threshold Scalar between 0 and 1. The relative spread fraction used to characterize revisions which
219+ # ' don't actually change very much. Default is .1, or 10% of the final value
220+ # '
221+ # ' @rdname revision_analysis
224222# ' @export
225- print.revision_behavior <- function (x , ... ) {
223+ print.revision_analysis <- function (x ,
224+ quick_revision = as.difftime(3 , units = " days" ) %> %
225+ difftime_approx_ceiling_time_delta(x $ time_type ),
226+ few_revisions = 3 ,
227+ abs_spread_threshold = NULL ,
228+ rel_spread_threshold = 0.1 ,
229+ ... ) {
226230 cli :: cli_h2(" An epi_archive spanning {.val {x$range_time_values[1]}} to {.val {x$range_time_values[1]}}." )
227231 cli :: cli_h3(" Min lag (time to first version):" )
228232 time_delta_summary(x $ revision_behavior $ min_lag , x $ time_type ) %> % print()
@@ -238,33 +242,31 @@ print.revision_behavior <- function(x, ...) {
238242 cli_li(num_percent(total_num_unrevised , total_num , " " ))
239243 total_quickly_revised <- sum( # nolint: object_usage_linter
240244 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 )
245+ time_delta_to_n_steps(quick_revision , x $ time_type )
242246 )
243- cli_inform(" Quick revisions (last revision within {format_time_delta(x$ quick_revision, x$time_type)}
247+ cli_inform(" Quick revisions (last revision within {format_time_delta(quick_revision, x$time_type)}
244248 of the `time_value`):" )
245249 cli_li(num_percent(total_quickly_revised , total_num , " " ))
246250 total_barely_revised <- sum( # nolint: object_usage_linter
247- x $ n_revisions < = x $ few_revisions
251+ x $ n_revisions < = few_revisions
248252 )
249- cli_inform(" Few revisions (At most {x$ few_revisions} revisions for that `time_value`):" )
253+ cli_inform(" Few revisions (At most {few_revisions} revisions for that `time_value`):" )
250254 cli_li(num_percent(total_barely_revised , total_num , " " ))
251255
252256 cli :: cli_h3(" Fraction of revised epi_key + time_values which have:" )
253257
254258 real_revisions <- x $ revision_behavior %> % filter(n_revisions > 0 ) # nolint: object_usage_linter
255259 n_real_revised <- nrow(real_revisions ) # nolint: object_usage_linter
256260 rel_spread <- sum( # nolint: object_usage_linter
257- real_revisions $ rel_spread <
258- x $ rel_spread_threshold ,
261+ real_revisions $ rel_spread < rel_spread_threshold ,
259262 na.rm = TRUE
260263 ) + sum(is.na(real_revisions $ rel_spread ))
261- cli_inform(" Less than {x$ rel_spread_threshold} spread in relative value:" )
264+ cli_inform(" Less than {rel_spread_threshold} spread in relative value:" )
262265 cli_li(num_percent(rel_spread , n_real_revised , " " ))
263266 abs_spread <- sum( # nolint: object_usage_linter
264- real_revisions $ spread >
265- x $ abs_spread_threshold
267+ real_revisions $ spread > abs_spread_threshold
266268 ) # nolint: object_usage_linter
267- cli_inform(" Spread of more than {x$ abs_spread_threshold} in actual value (when revised):" )
269+ cli_inform(" Spread of more than {abs_spread_threshold} in actual value (when revised):" )
268270 cli_li(num_percent(abs_spread , n_real_revised , " " ))
269271
270272 # time_type_unit_pluralizer[[time_type]] is a format string controlled by us
0 commit comments