Skip to content

Commit

Permalink
slightly clearer printing, renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
dsweber2 committed Jul 30, 2024
1 parent 8617ea7 commit 366e8b2
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 34 deletions.
6 changes: 3 additions & 3 deletions R/archive.R
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ new_epi_archive <- function(
nrow_before_compactify <- nrow(data_table)
# Runs compactify on data frame
if (is.null(compactify) || compactify == TRUE) {
data_table <- compactify_tibble(data_table, key_vars, compactify_tol)
data_table <- compactify(data_table, key_vars, compactify_tol)
}
# Warns about redundant rows if the number of rows decreased, and we didn't
# explicitly say to compactify
Expand Down Expand Up @@ -364,7 +364,7 @@ new_epi_archive <- function(
#' changed, and so is kept.
#' @keywords internal
#' @importFrom dplyr filter
compactify_tibble <- function(df, keys, tolerance = .Machine$double.eps^.5) {
compactify <- function(df, keys, tolerance = .Machine$double.eps^.5) {
df %>%
arrange(!!!keys) %>%
filter(if_any(
Expand All @@ -373,7 +373,7 @@ compactify_tibble <- function(df, keys, tolerance = .Machine$double.eps^.5) {
))
}

#' get the entries that `compactify_tibble` would remove
#' get the entries that `compactify` would remove
#' @keywords internal
#' @importFrom dplyr filter if_all everything
removed_by_compactify <- function(df, keys, tolerance) {
Expand Down
22 changes: 11 additions & 11 deletions R/revision_analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
#' afterwards at 150.
#' @param epi_arch an epi_archive to be analyzed
#' @param ... <[`tidyselect`][dplyr_tidy_select]>, used to choose the column to summarize. If empty, it
#' chooses the first. Currently only implemented for one column at a time
#' chooses the first. Currently only implemented for one column at a time.
#' @param drop_nas bool, drop any `NA` values from the archive? After dropping
#' `NA`'s compactify is run again to make sure there are no duplicate values
#' from occasions when the signal is revised to be NA, and then back to its
#' from occasions when the signal is revised to `NA`, and then back to its
#' immediately-preceding value.
#' @param print_inform bool, determines whether to print summary information, or
#' only return the full summary tibble
Expand Down Expand Up @@ -97,7 +97,7 @@ revision_summary <- function(epi_arch,
revision_behavior %>%
filter(!is.na(c_across(!!arg))) %>%
arrange(across(c(geo_value, time_value, all_of(keys), version))) %>% # need to sort before compactifying
compactify_tibble(c(keys, version), compactify_tol)
compactify(c(keys, version), compactify_tol)
} else {
revision_behavior <- epi_arch$DT
}
Expand Down Expand Up @@ -130,25 +130,25 @@ revision_summary <- function(epi_arch,
filter(is.na(c_across(!!arg))) %>% # nolint: object_usage_linter
nrow()
cli_inform("Fraction of all versions that are `NA`:")
cli_li(num_percent(total_na, nrow(epi_arch$DT)))
cli_li(num_percent(total_na, nrow(epi_arch$DT), "versions"))
}
total_num <- nrow(revision_behavior) # nolint: object_usage_linter
total_num_unrevised <- sum(revision_behavior$n_revisions == 0) # nolint: object_usage_linter
cli_inform("No revisions:")
cli_li(num_percent(total_num_unrevised, total_num))
cli_li(num_percent(total_num_unrevised, total_num, "entries"))
total_quickly_revised <- sum( # nolint: object_usage_linter
revision_behavior$max_lag <=
as.difftime(quick_revision, units = "days")
)
cli_inform("Quick revisions (last revision within {quick_revision}
{units(quick_revision)} of the `time_value`):")
cli_li(num_percent(total_quickly_revised, total_num))
cli_li(num_percent(total_quickly_revised, total_num, "entries"))
total_barely_revised <- sum( # nolint: object_usage_linter
revision_behavior$n_revisions <=
few_revisions
)
cli_inform("Few revisions (At most {few_revisions} revisions for that `time_value`):")
cli_li(num_percent(total_barely_revised, total_num))
cli_li(num_percent(total_barely_revised, total_num, "entries"))
cli_inform("")
cli_inform("Changes in Value:")

Expand All @@ -160,7 +160,7 @@ revision_summary <- function(epi_arch,
na.rm = TRUE
) + sum(is.na(real_revisions$rel_spread))
cli_inform("Less than {rel_spread_threshold} spread in relative value (only from the revised subset):")
cli_li(num_percent(rel_spread, n_real_revised))
cli_li(num_percent(rel_spread, n_real_revised, "revised entries"))
na_rel_spread <- sum(is.na(real_revisions$rel_spread)) # nolint: object_usage_linter
cli_inform("{units(quick_revision)} until within {within_latest*100}% of the latest value:")
difftime_summary(revision_behavior[["time_near_latest"]]) %>% print()
Expand All @@ -169,7 +169,7 @@ revision_summary <- function(epi_arch,
abs_spread_threshold
) # nolint: object_usage_linter
cli_inform("Spread of more than {abs_spread_threshold} in actual value (when revised):")
cli_li(num_percent(abs_spread, n_real_revised))
cli_li(num_percent(abs_spread, n_real_revised, "revised entries"))
}
return(revision_behavior)
}
Expand Down Expand Up @@ -227,8 +227,8 @@ spread_vec <- function(x) {

#' simple util for printing a fraction and it's percent
#' @keywords internal
num_percent <- function(a, b) {
glue::glue("{prettyNum(a, big.mark=',')} out of {prettyNum(b, big.mark=',')}
num_percent <- function(a, b, b_description) {
glue::glue("{prettyNum(a, big.mark=',')} out of {prettyNum(b, big.mark=',')} {b_description}
({round(a/b*100,digits=2)}%)")
}

Expand Down
9 changes: 9 additions & 0 deletions man/compactify.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions man/compactify_tibble.Rd

This file was deleted.

2 changes: 1 addition & 1 deletion man/num_percent.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/removed_by_compactify.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/revision_summary.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions tests/testthat/test-revision-latency-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ dummy_ex <- tibble::tribble(
as_epi_archive(compactify = FALSE)

test_that("revision_summary works for a dummy dataset", {
dummy_ex %>%
revision_summary() %>%
print(n = 10, width = 300)
expect_snapshot(dummy_ex %>% revision_summary() %>% print(n = 10, width = 300))
dummy_ex %>%
revision_summary(drop_nas = FALSE) %>%
print(n = 10, width = 300)
expect_snapshot(dummy_ex %>% revision_summary(drop_nas = FALSE) %>% print(n = 10, width = 300))
})
test_that("tidyselect is functional", {
Expand Down

0 comments on commit 366e8b2

Please sign in to comment.