Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update revision_summary #540

Open
wants to merge 32 commits into
base: lcb/rework-key_colnames
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
da28a28
Make `extra_keys =` into soft "deprecation" of a different behavior
brookslogan Oct 21, 2024
8b5d905
fix(revision_summary): use selected value col, not last col
brookslogan Oct 9, 2024
06c5d1b
Tweak revision_summary tidyselect, remove redundant arrange
brookslogan Oct 10, 2024
8c13f31
Clarify time_near_latest -> lag_near_latest
brookslogan Oct 10, 2024
1a74d75
fix(revision_summary): consider units&class in lag filter
brookslogan Oct 18, 2024
074e0a4
Fix compactification with dist_quantiles columns
brookslogan Oct 18, 2024
8bbcf16
Refactor/fix(?): Use time_delta helpers in revision_summary
brookslogan Dec 16, 2024
e405e2f
docs(epi_df.Rmd): immediate ungrouping + discuss completion effects
brookslogan Dec 19, 2024
09bd354
docs(epi_df.Rmd): editing pass on flusurv aggregation update
brookslogan Dec 19, 2024
edb1b9b
docs(epi_df.Rmd): general editing pass
brookslogan Dec 19, 2024
4473acb
feat(revision_summary): don't autoselect first var if != 1 var
brookslogan Dec 19, 2024
638b117
Add `time_delta_to_approx_difftime()` utils function
brookslogan Dec 19, 2024
2fe9b1a
fix(revision_summary): make min_waiting_period strict like docs
brookslogan Dec 20, 2024
be19854
feat(revision_summary)!: make `min_waiting_period` nonstrict
brookslogan Dec 20, 2024
826b927
Add difftime_approx_ceiling_time_delta helper, adj yearmonth difftime…
brookslogan Dec 20, 2024
3509ebc
Migrate time utils to new file
brookslogan Dec 20, 2024
ee00d42
Add unit_time_delta_fast and time add/sub helpers
brookslogan Dec 20, 2024
4405ab9
Add time_delta standardization helpers
brookslogan Dec 20, 2024
5de2eec
Change *_friendly and *_fast functions to an extra argument
brookslogan Dec 20, 2024
a1ebd09
Refactor some time_step <-> n_steps usage for clarity
brookslogan Dec 20, 2024
0707e71
feat+fix(revision_summary): expand time_type support + fix helpers
brookslogan Dec 20, 2024
1558f69
Add internal docs for additional time helpers
brookslogan Dec 20, 2024
deb2e8b
Add tests for default min_waiting_period x several time_types
brookslogan Dec 21, 2024
257f69c
Add internal roxygen stub of validate_slide_window_arg
brookslogan Jan 8, 2025
046fb70
Fill in some missing @param entries, links in time utils
brookslogan Jan 9, 2025
2e86b84
fix: complete partial rename (time_to -> lag_to in globalVariables)
brookslogan Jan 9, 2025
2692843
Fix potential `_` formatting issues + update (un)grouping in README.Rmd
brookslogan Jan 9, 2025
a0fe1d8
docs(slide.R): datatable:: -> data.table::
brookslogan Jan 9, 2025
7a7ce48
lint: uncomment redundant check for nicer organization
brookslogan Jan 9, 2025
386f51d
docs(revision_summary): update `drop_nas`, compactification, & param …
brookslogan Jan 9, 2025
8f223c2
lint: nolint indentation on one disagreement with styler
brookslogan Jan 9, 2025
d850083
minor code annotations, some logic ordering
dsweber2 Jan 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: epiprocess
Type: Package
Title: Tools for basic signal processing in epidemiology
Version: 0.10.1
Version: 0.10.2
Authors@R: c(
person("Jacob", "Bien", role = "ctb"),
person("Logan", "Brooks", , "lcbrooks+github@andrew.cmu.edu", role = c("aut", "cre")),
Expand Down Expand Up @@ -103,5 +103,6 @@ Collate:
'reexports.R'
'revision_analysis.R'
'slide.R'
'time-utils.R'
'utils.R'
'utils_pipe.R'
8 changes: 8 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,15 @@ export(time_column_names)
export(ungroup)
export(unnest)
export(validate_epi_archive)
export(vec_position_lag)
export(version_column_names)
import(epidatasets)
importFrom(checkmate,anyInfinite)
importFrom(checkmate,anyMissing)
importFrom(checkmate,assert)
importFrom(checkmate,assert_character)
importFrom(checkmate,assert_class)
importFrom(checkmate,assert_count)
importFrom(checkmate,assert_data_frame)
importFrom(checkmate,assert_false)
importFrom(checkmate,assert_function)
Expand Down Expand Up @@ -195,6 +197,7 @@ importFrom(rlang,caller_arg)
importFrom(rlang,caller_env)
importFrom(rlang,check_dots_empty)
importFrom(rlang,check_dots_empty0)
importFrom(rlang,dots_n)
importFrom(rlang,enquo)
importFrom(rlang,enquos)
importFrom(rlang,env)
Expand Down Expand Up @@ -235,5 +238,10 @@ importFrom(tidyselect,starts_with)
importFrom(tsibble,as_tsibble)
importFrom(utils,capture.output)
importFrom(utils,tail)
importFrom(vctrs,obj_check_vector)
importFrom(vctrs,vec_c)
importFrom(vctrs,vec_cast)
importFrom(vctrs,vec_data)
importFrom(vctrs,vec_equal)
importFrom(vctrs,vec_size)
importFrom(vctrs,vec_slice)
21 changes: 19 additions & 2 deletions R/archive.R
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,23 @@ removed_by_compactify <- function(df, keys, tolerance) {
)) # nolint: object_usage_linter
}

#' Lag entries in a vctrs-style vector by their position in the vector
#'
#' @importFrom checkmate assert_count
#' @importFrom vctrs obj_check_vector vec_slice vec_size
#' @keywords internal
#' @importFrom vctrs vec_c vec_slice vec_size
#' @export
vec_position_lag <- function(x, n) {
obj_check_vector(x)
assert_count(n)
if (length(x) == 0L) {
x
} else {
vec_c(rep(NA, n), vec_slice(x, seq_len(vec_size(x) - 1L)))
}
}

#' Checks to see if a value in a vector is LOCF
#' @description
#' LOCF meaning last observation carried forward. lags the vector by 1, then
Expand All @@ -378,8 +395,8 @@ removed_by_compactify <- function(df, keys, tolerance) {
#' @importFrom dplyr lag if_else near
#' @keywords internal
is_locf <- function(vec, tolerance) { # nolint: object_usage_linter
lag_vec <- dplyr::lag(vec)
if (typeof(vec) == "double") {
lag_vec <- vec_position_lag(vec, 1L)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a test example for why dplyr::lag doesn't work? You didn't really mention this or the reason for it in the PR

if (inherits(vec, "numeric")) { # (no matrix/array/general support)
res <- if_else(
!is.na(vec) & !is.na(lag_vec),
near(vec, lag_vec, tol = tolerance),
Expand Down
4 changes: 2 additions & 2 deletions R/epiprocess-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ utils::globalVariables(c(
".x", ".group_key", ".ref_time_value", "resid",
"fitted", ".response", "geo_value", "time_value",
"value", ".real", "lag", "max_value", "min_value",
"median_value", "spread", "rel_spread", "time_to",
"time_near_latest", "n_revisions", "min_lag", "max_lag"
"median_value", "spread", "rel_spread", "lag_to",
"lag_near_latest", "n_revisions", "min_lag", "max_lag"
))
19 changes: 15 additions & 4 deletions R/key_colnames.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,16 @@
#' @keywords internal
#' @export
key_colnames <- function(x, ..., exclude = character()) {
UseMethod("key_colnames")
provided_args <- rlang::call_args_names(rlang::call_match())
if ("extra_keys" %in% provided_args) {
lifecycle::deprecate_soft("0.9.6", "key_colnames(extra_keys=)", "key_colnames(other_keys=)")
redispatch <- function(..., extra_keys) {
key_colnames(..., other_keys = extra_keys)
}
redispatch(x, ..., exclude = exclude)
} else {
UseMethod("key_colnames")
}
}

#' @rdname key_colnames
Expand All @@ -44,7 +53,7 @@ key_colnames.data.frame <- function(x, ...,
assert_character(time_keys)
assert_character(other_keys)
assert_character(exclude)
keys = c(geo_keys, other_keys, time_keys)
keys <- c(geo_keys, other_keys, time_keys)
if (!all(keys %in% names(x))) {
cli_abort(c(
"Some of the specified key columns aren't present in `x`",
Expand All @@ -67,11 +76,13 @@ key_colnames.epi_df <- function(x, ...,
check_dots_empty0(...)
if (!identical(geo_keys, "geo_value")) {
cli_abort('If `x` is an `epi_df`, then `geo_keys` must be `"geo_value"`',
class = "epiprocess__key_colnames__mismatched_geo_keys")
class = "epiprocess__key_colnames__mismatched_geo_keys"
)
}
if (!identical(time_keys, "time_value")) {
cli_abort('If `x` is an `epi_df`, then `time_keys` must be `"time_value"`',
class = "epiprocess__key_colnames__mismatched_time_keys")
class = "epiprocess__key_colnames__mismatched_time_keys"
)
}
expected_other_keys <- attr(x, "metadata")$other_keys
if (is.null(other_keys)) {
Expand Down
Loading
Loading