DRDataRaft/ docs
GitHub ↗

dr_measure()

A successful publication result supplies its exact asset and release. Later publications do not change that input. Result-based measurement does not register definitions or write lineage; its manifest still contains all metric and input evidence needed by dr_report_release(). A live caller-owned lake is borrowed when available. Otherwise the saved configuration opens an owned read-only connection that closes before returning, including on errors.

Usage

\method{collect}{dr_measurement_set}(x, ...)

\method{print}{dr_measurement_set}(x, ...)

dr_measure(
  x,
  metric = NULL,
  by = character(),
  at = NULL,
  release = NULL,
  filters = list(),
  params = list(),
  record = NULL,
  metrics = NULL,
  period = c("each", "aggregate")
)

Arguments

x
Connected lake or successful dr_run_result. In-memory dataraft.core::dr_run() results support exploratory measurements with the same definitions. They cannot be recorded or saved in issued reports, even for approved metrics.


...
Reserved for future extensions.


metric
Single metric definition.


by
Grouping columns selected from the metric's permitted dimensions. Omitting by calculates an overall total, with a reminder when dimensions are available. Use by = character() to request an overall total explicitly.


at
Business date, or a vector for flow metrics.


release
Optional explicit product release id for a connected lake. For a publication result it must be omitted or match that exact release.


filters
Named list of exact-match filters on permitted dimensions.


params
Parameters passed to custom compute functions.


record
Record definition and lineage. Defaults to TRUE on a writable lake and FALSE on a read-only lake or publication result. Use a connected writable lake for record = TRUE. Unrecorded results still carry their complete metric definition and pinned release in the manifest. Exploratory metrics always default to record = FALSE and cannot be saved in reports.


metrics
Nonempty list of metric definitions for a measurement set. Optional unique names label metrics in the collected table. Supply either metric or metrics.


period
For metrics, "each" calculates each selected date separately; "aggregate" calculates across selected dates. Stock metrics still require one date. With at = NULL, dates are not split automatically.

Value

For metric, a tibble with a dr_manifest attribute. For metrics, a dr_measurement_set retaining each original result and manifest. dataraft.core::dr_collect() returns an ordinary long tibble with grouping columns, .metric, .period (a list column of selected dates), .unit and value. Grouped results are ordered by the requested dimensions using C collation so database row order does not change report identity.

Examples

\dontshow{if (requireNamespace("dataraft.lake", quietly = TRUE) && requireNamespace("duckdb", quietly = TRUE)) withAutoprint(\{ # examplesIf}
root <- tempfile("dataraft-example-")
config <- dataraft.lake::dr_lake_config(
  dataraft.lake::dr_registry_duckdb(file.path(root, "lake.db")),
  dataraft.lake::dr_storage_local(file.path(root, "data")),
  landing = file.path(root, "landing"), backend = "duckdb"
)
lake <- dataraft.lake::dr_connect_lake(config)
path <- file.path(root, "orders.csv")
utils::write.csv(data.frame(order_id = 1:2, amount = c(25, 75)), path,
  row.names = FALSE)
source <- dataraft.core::dr_source_file("orders.file", path, reader = utils::read.csv)
contract <- dataraft.core::dr_contract(
  "orders", version = "1.0.0", columns =
  c(order_id = "integer", amount = "numeric"), key = "order_id"
)
release <- dataraft.core::dr_product("orders", contract = contract, code_version = "v1") |>
  dataraft.core::dr_add_source(source) |> dataraft.core::dr_publish(to = lake)
metric <- dr_metric(
  "orders.total", "orders", expr = sum(amount), time_behavior = "flow",
  unit = "EUR", owner = "Analytics", description = "Total order value",
  approved = TRUE, code_version = "v1"
)
release |> dr_measure(metric)
dataraft.lake::dr_disconnect_lake(lake)
unlink(root, recursive = TRUE)
\dontshow{\}) # examplesIf}
Documentation source snapshot · View source at 513e09e ↗
Code examples are documented source examples; they are not executed in this website build.

Search documentation

Search functions, packages and guides.