parse_rules: Parse association rules into a reusable, layout-agnostic...

View source: R/parse_rules.R

parse_rulesR Documentation

Parse association rules into a reusable, layout-agnostic structure

Description

Converts association rules into a normalized representation for downstream layout/rendering. Accepts either: - a 'data.frame' with **required** columns 'Antecedent', 'Consequence', 'Support', 'Confidence', 'Fitness', or - a native 'niarules' rules object (which is exported to CSV internally via 'niarules::write_association_rules_to_csv()' and then parsed).

The output separates **items** from **rules** and uses stable **0-based** item identifiers suitable for cross-language use.

Usage

parse_rules(arules = NULL)

Arguments

arules

A 'data.frame' with columns 'Antecedent', 'Consequence', 'Support', 'Confidence', 'Fitness', **or** a 'niarules' rules object.

Details

**Input requirements** - 'Antecedent', 'Consequence': character encodings of itemsets per rule. - 'Support', 'Confidence', 'Fitness': numeric metrics; 'Fitness' is interpreted as the **lift-like** metric and is exposed as 'lift' in the returned 'rules'.

When 'arules' is not a 'data.frame', the function requires the **niarules** package at runtime to serialize the rules to CSV. Missing required columns trigger an error.

**Output schema** - 'items' ('data.frame'): 'item_id' (integer, **0-based**), 'label', 'feature', 'kind', 'category_value', 'lo', 'hi', 'incl_low', 'incl_high', 'op', 'label_long', 'label_short'. - 'rules' ('data.frame'): 'rule_id', 'support', 'confidence', 'lift', 'lhs_item_ids' (list of integer vectors; **0-based ids**), 'rhs_item_ids' (list of integer vectors; **0-based ids**), 'antecedent_length', 'consequent_length'.

**Indexing note** 'item_id' values are **0-based** for stability across languages. In R, convert to 1-based with 'items$item_id + 1L' if needed.

Value

A list with components: - 'items': 'data.frame' describing unique items, - 'rules': 'data.frame' describing association rules.


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