Maintains a local mirror of the Enhetsregisteret by applying incremental CDC (change data capture) events to a persistent state table. On first run, bootstraps from a bulk download. Subsequent runs poll the CDC endpoints from the last cursor position and apply mutations.
Arguments
- types
Character vector of streams to sync. Default syncs all four.
- size
Integer. CDC page size per API call (max 10000).
- roller_method
One of
"bulk"(default) or"cdc"."bulk"downloads the full totalbestand (~131 MB) and computes a field-level diff against previous state — fast and produces granular changelogs."cdc"fetches current roles per-org via the API for each CDC event — slower but provides sub-daily attribution when syncing multiple times per day.- verbose
Logical. Print progress messages.
Details
Four state files are maintained:
enheter.parquet— main entities (~1M rows)underenheter.parquet— sub-entities (~500K rows)roller.parquet— all roles (~3.4M rows)paategninger.parquet— registry annotations
Every mutation is logged to a Hive-partitioned changelog
under state/changelog/sync_date={date}/. The changelog
drives brreg_changes() and brreg_flows().
Write ordering
Changelog is written first (WAL), then state files, then cursor. If a crash occurs between state and cursor, the next sync replays from the old cursor. Mutations are idempotent (upsert by org_nr), so replay is safe.
See also
brreg_sync_status() to check current state,
brreg_changes() to query the changelog,
brreg_flows() for entry/exit counts.
Other tidybrreg data management functions:
brreg_annotation_summary(),
brreg_annotations(),
brreg_status(),
brreg_sync_status(),
diff_roller_state(),
read_changelog()
Examples
if (FALSE) { # interactive() && curl::has_internet()
# \donttest{
brreg_sync()
brreg_sync_status()
# }
}