R6 class representing Cohort object.
R6 class representing Cohort object.
Methods
Method new()
Create Cohort object.
Arguments
sourceSource object created with set_source.
...Steps definition (optional). Can be also defined as a sequence of filters - the filters will be added to the first step.
run_flowIf `TRUE`, data flow is run after the operation is completed.
compute_statsIf `TRUE` (default), filter statistics are computed and stored after each step. Set to `FALSE` to skip stats computation (useful for metadata-only operation).
propagate_domainsDomain propagation mode between steps. One of `"none"` (default, no propagation), `"filter"` (derive from previous step filter values), `"stats"` (derive from stored statistics), or `"data"` (scan filtered data). `"stats"` requires `compute_stats = TRUE`; use `"data"` for the stats-free equivalent.
hookList of hooks describing methods before/after the Cohort is created. See hooks for more details.
Method add_source()
Add Source to Cohort object.
Arguments
sourceSource object created with set_source.
Method update_source()
Update Source in the Cohort object.
Arguments
sourceSource object created with set_source.
keep_stepsIf `TRUE`, steps definition remains unchanged when updating source. If `FALSE` steps configuration is deleted. If vector of type integer, specified steps will remain.
run_flowIf `TRUE`, data flow is run after the operation is completed.
hookList of hooks describing methods before/after the Cohort is created. See hooks for more details.
Method get_propagate_domains_mode()
Return the configured domain propagation mode.
One of `"none"`, `"filter"`, `"stats"` or `"data"`. Read-only; the mode is fixed at construction. UI layers can inspect it (e.g. to validate that a domain-based rendering strategy is compatible with the cohort).
Method remove_step()
Remove filtering step definition
Arguments
step_idId of the step to remove.
run_flowIf `TRUE`, data flow is run after the operation is completed.
hookList of hooks describing methods before/after the Cohort is created. See hooks for more details.
Method add_filter()
Add filter definition
Arguments
filterFilter definition created with filter.
step_idId of the step to add the filter to. If missing, filter is added to the last step.
run_flowIf `TRUE`, data flow is run after the operation is completed.
hookList of hooks describing methods before/after the Cohort is created. See hooks for more details.
Method remove_filter()
Remove filter definition
Arguments
step_idId of the step from which filter should be removed.
filter_idId of the filter to be removed.
run_flowIf `TRUE`, data flow is run after the operation is completed.
hookList of hooks describing methods before/after the Cohort is created. See hooks for more details.
Method update_filter()
Update filter definition
Arguments
step_idId of the step where filter is defined.
filter_idId of the filter to be updated.
...Filter parameters that should be updated.
activeMark filter as active (`TRUE`) or inactive (`FALSE`).
run_flowIf `TRUE`, data flow is run after the operation is completed.
hookList of hooks describing methods before/after the Cohort is created. See hooks for more details.
hook_argsNamed list of extra arguments passed to pre/post hooks.
Method get_state()
Get Cohort configuration state.
Method restore()
Arguments
stateList or JSON string containing steps and filters configuration.
modifierFunction two parameters combining the previous and provided state. The returned state is then restored.
run_flowIf `TRUE`, data flow is run after the operation is completed.
hookList of hooks describing methods before/after the Cohort is created. See hooks for more details.
Method get_data()
Get step related data
Method plot_data()
Plot filter specific data summary.
Method calc_stats()
Get Cohort related statistics.
Arguments
step_idWhen `filter_id` specified, `step_id` precises from which step the filter comes from. Otherwise data from specified step is used to calculate required statistics.
filter_idIf not missing, filter related data statistics are returned.
...Specific parameters passed to filter related method.
stateShould the stats be calculated on data before ("pre") or after ("post") filtering in specified step.
Method show_help()
Show source data or filter description
Usage
Cohort$show_help(
field,
step_id,
filter_id,
modifier = getOption("cb_help_modifier", default = function(x) x)
)Arguments
fieldName of the source description field provided as `description` argument to set_source. If missing, `step_id` and `filter_id` are used to return filter description.
step_idId of the filter step to return description of.
filter_idId of the filter to return description of.
modifierA function taking the description as argument. The function can be used to modify its argument (convert to html, display in browser etc.).
Method get_code()
Return reproducible data filtering code.
Arguments
include_sourceIf `TRUE` source generating code will be included.
include_methodsWhich methods definition should be included in the result.
include_actionWhich action should be returned in the result. `pre_filtering`/`.post_filtering` - to include data transformation before/after filtering. s`run_binding` - data binding transformation.
modifierA function taking data frame (storing reproducible code metadata) as an argument, and returning data frame with `expr` column which is then combined into a single expression (final result of `get_code`). See .repro_code_tweak.
mark_stepInclude information which filtering step is performed.
...Other parameters passed to tidy_source.
Method run_flow()
Trigger data calculations sequentially.
Arguments
min_stepStep id starting from the calculation will be started.
hookList of hooks describing methods before/after the Cohort is created. See hooks for more details.
Method run_step()
Trigger data calculations for selected step.
Arguments
step_idId of the step for which to run data calculation.
hookList of hooks describing methods before/after the Cohort is created. See hooks for more details.
Method bind_data()
Run data binding for selected step. See more at binding-keys.
Method update_stats()
Update filter or step statistics. Computes and stores step and filter attached data statistics such as number of data rows, filter choices or frequencies.
Arguments
step_idId of the step for which statistics should be computed. If `filter_id` is not missing, the parameter describes id of the step where filter should be found.
filter_idId of the filter for which statistics should be computed.
stateShould statistics be computed on data before ("pre") or after ("post") filtering in specified step.
nameOptional name(s) of the individual filter statistics to (re)compute. When supplied (filter-level only), only those statistics are computed and merged into the stored entry, leaving any other stored statistics untouched. When missing, the full statistics set is computed.
Method get_stats()
Return step or filter specific statistics.
Usage
Cohort$get_stats(
step_id,
filter_id,
state = "post",
.recalc_when_missing = TRUE,
name = NULL
)Arguments
step_idId of the step for which stored statistics should be returned If `filter_id` is not missing, the parameter describes id of the step where filter should be found.
filter_idId of the filter for which stored statistics should be returned.
stateShould statistics be returned on data before ("pre") or after ("post") filtering in specified step.
.recalc_when_missingShould the function compute statistics automatically when not computed yet?
nameOptional name of a single filter statistic to return (e.g. "choices", "n_data"). When supplied (filter-level only) the method returns just that statistic and, if recomputation is needed, computes only it instead of the whole statistics set. When missing, the full stored entry (a list of all statistics) is returned.
Method set_pending()
Mark step as pending or resolved.
Arguments
step_idId of the step.
pendingLogical; `TRUE` to mark pending, `FALSE` to resolve.
hookList of hooks describing methods before/after the Cohort is created. See hooks for more details.
Method set_pending_cascade()
Mark a step and all the steps after it as pending.
A change to step `step_id`'s filters invalidates that step and every step downstream (each step's input is the previous step's output). Used by the filter/step mutating methods so the GUI greys all affected steps via the `post_set_pending_hook`.
Method set_domain()
Silently set a filter's domain.
Internal setter used by domain propagation (.propagate_domains). Writes `filter@domain` directly **without** firing the `update_filter` hooks and **without** triggering `run_flow`, which prevents the per-hop hook re-entry that would otherwise occur if domains were applied through `update_filter`. Does not itself trigger further propagation.
Method propagate_domains_to()
Recompute a target step's domains from its parent and signal the change.
Thin wrapper around .propagate_domains that runs propagation for `target_id` (computing its filters' domains from step `target_id - 1`) and then fires `post_propagate_domains_hook` so UI layers can refresh the affected step's inputs. No-op when propagation is disabled or the target step is absent / has no parent.
Usage
Cohort$propagate_domains_to(
target_id,
hook = get_hook("post_propagate_domains_hook")
)Arguments
target_idId of the step whose domains should be recomputed.
hookList of hooks describing methods before/after the Cohort is created. See hooks for more details.
Method propagate_filter_domains()
Eagerly propagate `"filter"`-mode domains to a target step and all steps after it.
`"filter"` mode needs no computed data, so domains can be (re)established immediately when the step structure changes. Because each step's domain depends on every previous step, this recomputes `from_target` and cascades downstream ascending. No-op unless the propagation mode is `"filter"`.
