Given a base snapshot and a stream of CDC updates from
brreg_updates(), reconstruct the state of the register at any
arbitrary date. Uses dplyr::rows_upsert() for Ny/Endring events
and dplyr::rows_delete() for Sletting events, applied
chronologically.
Usage
brreg_replay(base, updates, target_date = Sys.Date(), cols = NULL)Arguments
- base
A tibble from
brreg_download(),brreg_import(), or a snapshot read viabrreg_open(). Must containorg_nr.- updates
A tibble from
brreg_updates()withinclude_changes = TRUE. Must containorg_nr,change_type,timestamp, andchanges(list-column of patch tibbles).- target_date
Date. Reconstruct state as of this date. Only updates with
timestamp <= target_dateare applied.- cols
Character vector of columns to track. If
NULL, all columns present inbaseare used.
Value
A tibble with the same columns as base, reflecting
all applied changes up to target_date. Attribute
replay_info records the number of inserts, updates, and
deletes applied.
Limitations
The brreg CDC stream provides only new values (not old values)
in RFC 6902 JSON Patch format, and field-level changes are only
available from September 2025. Before that date, only the
change type (Ny/Endring/Sletting) is recorded — field-level
replay is not possible for those periods. Use brreg_events()
(snapshot diff) for pre-September 2025 field-level changes.
See also
brreg_panel() for multi-snapshot panels,
brreg_updates() to fetch the CDC stream.
Other tidybrreg panel functions:
as_brreg_tsibble(),
brreg_change_summary(),
brreg_changes(),
brreg_events(),
brreg_flows(),
brreg_panel(),
brreg_series()
Examples
if (FALSE) {
base <- brreg_download(type_output = "tibble")
updates <- brreg_updates(since = Sys.Date() - 30,
size = 10000, include_changes = TRUE)
state <- brreg_replay(base, updates, target_date = Sys.Date())
}