Skip to contents

Download today's complete register and save as a Parquet partition in the local snapshot store. Each call adds one partition to a Hive-partitioned dataset at tools::R_user_dir("tidybrreg", "data")/{type}/snapshot_date={date}/. Subsequent calls to brreg_panel() and brreg_events() query this partitioned dataset lazily via arrow::open_dataset().

Usage

brreg_snapshot(
  type = c("enheter", "underenheter", "roller"),
  format = c("csv", "json"),
  date = Sys.Date(),
  force = FALSE,
  ask = interactive()
)

Arguments

type

One of "enheter" (main entities, default), "underenheter" (sub-entities / establishments), or "roller" (all roles for all entities, via /roller/totalbestand). Roller snapshots parse the nested JSON into a flat tibble matching brreg_roles() output.

format

Download format: "csv" (default for enheter/underenheter) or "json". JSON captures additional fields not present in CSV (e.g. kapital, vedtektsfestetFormaal, paategninger). Roller is always JSON regardless of this parameter.

date

Date for this snapshot (default: today). Used as the partition key, not as an API parameter — the brreg bulk endpoint always returns the current-day state.

force

Logical. If TRUE, overwrite an existing partition for this date. Default FALSE skips if partition exists.

ask

Logical. If TRUE (the default in interactive sessions), prompt before downloading ~145 MB.

Value

The file path to the written Parquet partition (invisibly).

See also

brreg_import() to add historical snapshots from CSV files, brreg_snapshots() to list available snapshots, brreg_panel() to construct panels from accumulated snapshots.

Other tidybrreg snapshot functions: brreg_cleanup(), brreg_data_dir(), brreg_import(), brreg_manifest(), brreg_open(), brreg_snapshots()

Examples

if (FALSE) { # interactive() && curl::has_internet() && tidybrreg:::parquet_tier() != "none"
# \donttest{
brreg_snapshot()
brreg_snapshots()
# }
}