You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#' @title Execute time-intelligence or segments class objects to return the underlying transformed table
107
107
#' @name calculate
108
108
#' @param x ti object
109
+
#' @description
110
+
#' The `calculate()` function takes an object created by a time function (like `ytd()`, `mtd()`, or `qtd()`) or a segment function (like `cohort()` or `abc()`) and executes the underlying transformation logic.
111
+
#' It translates the function blueprint into an actionable query, returning the final data table.
112
+
#'
113
+
#' @details
114
+
#' The TI and segment functions in **fpaR**—such as `ytd()` or `cohort()` and others—are designed to be **lazy and database-friendly**.
115
+
#' They do not perform the heavy data transformation immediately.
116
+
#' Instead, they return a blueprint object (of class `ti`,`segment_abc` or `segment_cohort`) that contains all the parameters and logic needed for the calculation.
117
+
#'
118
+
#' **`calculate()`** serves as the **execution engine**.
119
+
#'
120
+
#' When called, it interprets the blueprint and generates optimized R code or SQL code (using the `dbplyr` package) that is then executed efficiently on the data source, whether it's an in-memory `tibble` or a remote database backend (like `duckdb` or `snowflake`).
121
+
#' This approach minimizes data transfer and improves performance for large datasets.
122
+
#'
123
+
#' The resulting table will be sorted by the relevant date column to ensure the correct temporal ordering of the calculated metrics.
0 commit comments