parse_rules_cpp: Low-level C++ parser for association rules

View source: R/RcppExports.R

parse_rules_cppR Documentation

Low-level C++ parser for association rules

Description

'parse_rules_cpp()' is the Rcpp-exposed engine behind parse_rules. It accepts a data frame of association rules and returns a layout-agnostic parsed structure consisting of an items table and a rules table. This function is exported by Rcpp primarily for internal use and testing.

Usage

parse_rules_cpp(rules_df)

Arguments

rules_df

A data frame with the required columns:

  • Antecedent (character)

  • Consequence (character)

  • Support (numeric)

  • Confidence (numeric)

  • Fitness (numeric; treated as lift by convention)

Details

Parsing rules

  • Both LHS and RHS are split on "," or "&" outside of brackets; leading/trailing whitespace is trimmed.

  • A single outer brace pair {...} on RHS is stripped if present.

  • Supported item syntaxes:

    • Categorical equality: feature = value (value may be quoted).

    • Numeric interval: feature in [lo, hi], (lo, hi], etc.

    • Relational: feature >= x, > x, <= x, < x.

  • For relational items, the unused bound is set to NA.

  • Fitness is carried through as lift.

Value

A list with two data frames:

items

Columns:

  • item_id: integer, 0-based stable ID within this parsed object.

  • label: original item string.

  • feature: base feature name.

  • kind: one of "numeric", "categorical", "set", "unknown".

  • category_value: categorical value (quotes removed).

  • lo, hi: numeric bounds (may be NA).

  • incl_low, incl_high: logical inclusivity flags.

  • op: one of "<", "<=", ">", ">=", "=", "in".

  • label_long, label_short: preformatted interval labels.

rules

Columns:

  • rule_id: 1-based rule index (for display).

  • support, confidence, lift: rule-level metrics.

  • lhs_item_ids, rhs_item_ids: list-columns of integer vectors of 0-based item_ids.

  • antecedent_length, consequent_length: integer lengths of LHS/RHS.

Errors

Throws an error if required columns are missing or have inconsistent lengths.


niarules documentation built on Sept. 15, 2025, 5:08 p.m.