Skip to contents

Derives one deterministic integer-day offset per subject using keyed HMAC-SHA-256. Exact elapsed intervals are preserved. Full shifted dates are pseudonymized personal data, not a HIPAA Safe Harbor output.

Usage

dateShift(
  dates,
  subject_id,
  key,
  range_days = c(-3650L, 3650L),
  inverse = FALSE
)

Arguments

dates

A Date or POSIXct vector.

subject_id

One subject ID or a vector aligned to dates.

key

Raw vector of at least 32 cryptographically random bytes.

range_days

Inclusive integer offset range.

inverse

Apply the exact negative keyed offset.

Value

A vector with the same length and date class.

Examples

key <- openssl::rand_bytes(32)
visits <- as.Date(c("2026-01-05", "2026-02-02", "2026-03-09"))
# One deterministic per-subject offset; exact intervals are preserved.
shifted <- dateShift(visits, subject_id = "subject-a", key = key)
all(diff(shifted) == diff(visits))
#> [1] TRUE