Skip to contents

Checks whether a vector of dates forms a complete, uninterrupted sequence between its minimum and maximum values. If missing dates are detected, they are printed using dput() for easy reuse and the function returns FALSE invisibly.

Usage

ngr_chk_dt_complete(
  x,
  units = "days",
  dates_print = TRUE,
  dates_capture = FALSE
)

Arguments

x

Date A vector of dates to check for completeness.

units

character Optional. A single string giving the time unit for the sequence passed to base::seq.Date(). Default is "days".

dates_print

logical Optional. Whether to print missing dates to the console using dput() when gaps are detected. Default is TRUE.

dates_capture

logical Optional. Whether to capture and return the missing dates as an object when gaps are detected. Default is FALSE.

Value

If dates_capture = FALSE (default), returns TRUE invisibly if no dates are missing and FALSE invisibly if one or more dates are missing.

If dates_capture = TRUE, returns the missing dates as a Date vector (invisibly) when gaps are detected, and TRUE invisibly when no dates are missing.

Details

The function computes a full date sequence using base::seq.Date() from min(x) to max(x) and compares it to the unique values of x using base::setdiff(). Missing dates, if any, are printed with dput() so they can be copied directly into code or tests.

See also

Examples

dates_ok <- as.Date("2024-01-01") + 0:4
ngr_chk_dt_complete(dates_ok)

dates_bad <- as.Date(c("2024-01-01", "2024-01-02", "2024-01-04"))
ngr_chk_dt_complete(dates_bad)
#> ! There are 1 missing date:
#> "2024-01-03"