Skip to contents

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 via brreg_open(). Must contain org_nr.

updates

A tibble from brreg_updates() with include_changes = TRUE. Must contain org_nr, change_type, timestamp, and changes (list-column of patch tibbles).

target_date

Date. Reconstruct state as of this date. Only updates with timestamp <= target_date are applied.

cols

Character vector of columns to track. If NULL, all columns present in base are 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())
}