dr_metric()
Define a reusable calculation, such as a total or cancellation rate, for a
data product. Choose its grouping columns, unit and date behavior, then
calculate it with
dr_measure().
Usage
dr_metric(
id,
product,
expr = NULL,
compute = NULL,
dimensions = character(),
time_column = NULL,
time_behavior = if (is.null(time_column)) "flow" else "stock",
unit = "",
owner = "",
description = "",
version = "1.0.0",
approved = FALSE,
na_policy = "reject",
empty_policy = "error",
code_version = NULL,
input_columns = NULL
)Arguments
- id, version
- Identity and version.
- product
- Input asset id.
- expr
- Tidy evaluation summary expression, e.g. sum(reserve).
- compute
- Alternative function(data, dimensions, params) for complex metrics.
- dimensions
- Permitted grouping columns.
- time_column
- Column representing the business date.
- time_behavior
stockrequires exactly one selected date;flowmay span dates. Defaults to stock whentime_columnis supplied, otherwise flow.- unit
- Optional unit.
- owner, description
- Optional business metadata.
- approved
- Whether business review is complete.
- na_policy
- Policy description; must be consistent with the expression.
- empty_policy
- Policy description.
- code_version
- Version of metric code and dependencies. Required for approved definitions; exploratory definitions may omit it.
- input_columns
- Optional explicit input columns for dynamic expressions or custom functions. Known expression columns are always checked as well.
Value
Metric specification. Reports execute it directly without an LLM.
Examples
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"
)
metricDocumentation source snapshot · View source at 513e09e ↗
Code examples are documented source examples; they are not executed in this website build.
Code examples are documented source examples; they are not executed in this website build.