Skip to content

Commit 839e921

Browse files
committed
Fix compactification with dist_quantiles columns
1 parent e994f52 commit 839e921

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

NAMESPACE

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,14 @@ export(time_column_names)
9999
export(ungroup)
100100
export(unnest)
101101
export(validate_epi_archive)
102+
export(vec_position_lag)
102103
export(version_column_names)
103104
importFrom(checkmate,anyInfinite)
104105
importFrom(checkmate,anyMissing)
105106
importFrom(checkmate,assert)
106107
importFrom(checkmate,assert_character)
107108
importFrom(checkmate,assert_class)
109+
importFrom(checkmate,assert_count)
108110
importFrom(checkmate,assert_data_frame)
109111
importFrom(checkmate,assert_function)
110112
importFrom(checkmate,assert_int)
@@ -232,4 +234,8 @@ importFrom(tidyselect,starts_with)
232234
importFrom(tsibble,as_tsibble)
233235
importFrom(utils,capture.output)
234236
importFrom(utils,tail)
237+
importFrom(vctrs,obj_check_vector)
238+
importFrom(vctrs,vec_c)
235239
importFrom(vctrs,vec_cast)
240+
importFrom(vctrs,vec_size)
241+
importFrom(vctrs,vec_slice)

R/archive.R

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,23 @@ removed_by_compactify <- function(df, keys, tolerance) {
385385
)) # nolint: object_usage_linter
386386
}
387387

388+
#' Lag entries in a vctrs-style vector by their position in the vector
389+
#'
390+
#' @importFrom checkmate assert_count
391+
#' @importFrom vctrs obj_check_vector vec_slice vec_size
392+
#' @keywords internal
393+
#' @importFrom vctrs vec_c vec_slice vec_size
394+
#' @export
395+
vec_position_lag <- function(x, n) {
396+
# obj_check_vector(x)
397+
assert_count(n)
398+
if (length(x) == 0L) {
399+
x
400+
} else {
401+
vec_c(rep(NA, n), vec_slice(x, seq_len(vec_size(x) - 1L)))
402+
}
403+
}
404+
388405
#' Checks to see if a value in a vector is LOCF
389406
#' @description
390407
#' LOCF meaning last observation carried forward. lags the vector by 1, then
@@ -394,8 +411,8 @@ removed_by_compactify <- function(df, keys, tolerance) {
394411
#' @importFrom dplyr lag if_else near
395412
#' @keywords internal
396413
is_locf <- function(vec, tolerance) { # nolint: object_usage_linter
397-
lag_vec <- dplyr::lag(vec)
398-
if (typeof(vec) == "double") {
414+
lag_vec <- vec_position_lag(vec, 1L)
415+
if (inherits(vec, "numeric")) { # (no matrix/array/general support)
399416
res <- if_else(
400417
!is.na(vec) & !is.na(lag_vec),
401418
near(vec, lag_vec, tol = tolerance),

man/vec_position_lag.Rd

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

0 commit comments

Comments
 (0)