Learn R Programming

nuggets

Fast and extensible pattern mining in R - fuzzy association rules, conditional correlations, and contrast patterns

nuggets is a package for R providing a fast and extensible framework for discovering interesting patterns in tabular data. It can find association rules, contrasts, subgroup patterns, conditional correlations, and other patterns defined by user-specified evaluation functions. Both Boolean and fuzzy predicates are supported. Efficient implementation enables pattern discovery on large and dense data sets. Package includes methods for visualization and supports interactive exploration through integrated Shiny applications.

What Patterns Can You Discover?

  • Association Rules: “University educated people in middle age working in IT have high income” - identify conditions that strongly predict specific outcomes.
  • Conditional Correlations: “Study time correlates with test score on hard exams” - discover relationships between variables that only hold under certain conditions .
  • Complement Contrasts: “Smokers have lower life expectancy than non-smokers” - find subgroups with significantly different characteristics from the rest.
  • Baseline Contrasts: “Measurement error differs from zero when using tool A” - detect when a variable deviates significantly from a baseline under specific conditions.
  • Paired Contrasts: “Ice cream sales exceed tea sales on sunny days” – compare paired measurements within specific contexts.
  • Custom Patterns: Define your own evaluation functions for specialized pattern mining.

Why nuggets?

arules is the established R framework for transaction-based association-rule and frequent-itemset mining. The nuggets package takes a broader approach: it searches combinations of conditions and evaluates the observations they select. This makes association rules just one of several types of patterns that can be discovered.

Key advantages of nuggets include:

  • Beyond association rules - discover associations, contrasts, subgroup patterns, conditional correlations, and other patterns defined by your own evaluation function.
  • Boolean and fuzzy predicates - work with both crisp conditions and fuzzy predicates, allowing patterns to express gradual concepts such as young, high income, or strongly associated.
  • Works naturally with ordinary data frames - search directly in tabular R data rather than requiring the data to be converted into a transaction representation first.
  • Numeric and categorical data - combine conditions on different types of variables and, where appropriate, use partition() to construct meaningful predicates from numeric or factor variables.
  • Extensible pattern discovery - dig() provides a general mechanism for searching candidate conditions and evaluating the resulting subsets of observations with arbitrary user-defined functions.
  • Fast pattern search - implemented in C++ with performance in mind, including efficient processing of large and dense datasets.
  • Visualization - unique tools for visualizing discovered patterns and their relationships.
  • Interactive exploration - inspect and explore discovered patterns using the package’s Shiny app.

Fast on Dense Datasets

A lot of effort has been put into optimizing the performance of the package, especially for dense datasets. The core algorithms are implemented in C++ and use single-instruction multiple-data (SIMD) operations to speed up the operations.

On a randomly generated dataset with 1 million rows and 15 columns, association rules with at most 5 items in the antecedent, a support above 0.001, and a confidence above 0.5 were searched. The total times, including reading the data from the CSV file, searching for rules, and writing the result back to CSV, on a Linux desktop computer with standard installations of the packages, were as follows:

  • nuggets (R, boolean logic): 1.4 s
  • arules - ECLAT (R, boolean logic): 2.9 s
  • arules - Apriori (R, boolean logic): 3.3 s

Fuzzy variant of association rules, which is much more computationally intensive:

  • nuggets (R, fuzzy logic): 12.0 s

For comparison, two Python libraries performed as follows:

  • cleverminer (Python, boolean logic): 1m 15.0s
  • mlxtend (Python, boolean logic, frequent itemsets only): 4h 11m 22.5s

Installation

To install the stable version of nuggets from CRAN, type the following command within the R session:

install.packages("nuggets", dependencies = TRUE)

You can also install the development version of nuggets from GitHub with:

install.packages("devtools")
devtools::install_github("beerda/nuggets")

To start using the package, load it to the R session with:

library(nuggets)

Minimal Example

The following example demonstrates how to use nuggets to find association rules in the built-in mtcars dataset:

# Preprocess: dichotomize and fuzzify numeric variables
cars <- mtcars |>
    partition(cyl, vs:gear, .method = "dummy") |>
    partition(carb, .method = "crisp", .breaks = c(0, 3, 10)) |>
    partition(mpg, disp:qsec, .method = "triangle", .breaks = 3)

# Search for associations among conditions
rules <- dig_associations(cars,
                          antecedent = everything(),
                          consequent = everything(),
                          max_length = 4,
                          min_support = 0.1)

# Add various interest measures
rules <- add_interest(rules)

# Explore the found rules interactively
explore(rules, cars)

Documentation

Read the full documentation of the nuggets package.

Vignettes

The package currently includes the following vignettes:

Contributing

Contributions, suggestions, and bug reports are welcome. Please submit issues on GitHub.

License

This package is licensed under the GPL-3 license.

It includes third-party code licensed under BSD-2-Clause, BSD-3-Clause, and GPL-2 or later licenses. See inst/COPYRIGHTS for details.

References

Burda, M. Accelerating Pattern Mining on Fuzzy Data by Packing Truth Values into Blocks of Bits. Applied Soft Computing. 2026, 191 (April 2026), ISSN 1568-4946.

Copy Link

Version

Install

install.packages('nuggets')

Monthly Downloads

348

Version

2.2.3

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Michal Burda

Last Published

August 20th, 2026

Functions in nuggets (2.2.3)

explore.baseline_contrasts

Show interactive application to explore baseline contrasts
explore.correlations

Show interactive application to explore conditional correlations
explore.paired_baseline_contrasts

Show interactive application to explore paired baseline contrasts
explore.associations

Show interactive application to explore association rules
format_condition

Format a vector of predicates into a condition string
fire

Obtain truth-degrees of conditions
dig_grid

Search for grid-based rules
explore.complement_contrasts

Show interactive application to explore complement contrasts
dig_tautologies

Find tautologies or "almost tautologies" in a dataset
dig_paired_baseline_contrasts

Search for conditions that provide significant differences between paired variables
is_subset

Determine whether one vector is a subset of another
is_degree

Test whether an object contains numeric values from the interval \([0,1]\)
is_condition

Check whether a list of character vectors contains valid conditions
geom_diamond

Geom for drawing diamond plots of lattice structures
is_logicalish

Check if an object is logical or numeric with only 0s and 1s
parse_condition

Convert condition strings into lists of predicate vectors
nuggets-package

nuggets: Fast and Extensible Pattern Discovery in Tabular Data
is_nugget

Test whether an object is a nugget
nugget

Create a nugget object of a given flavour
is_almost_constant

Test whether a vector is almost constant
permute

Generate all permutations of a vector
remove_almost_constant

Remove almost constant columns from a data frame
reexports

Objects exported from other packages
values

Extract values from predicate names
remove_ill_conditions

Remove invalid conditions from a list
shorten_condition

Shorten predicates within conditions
var_grid

Create a tibble of combinations of selected column names
plot_contingency.data.frame

Plot a mosaic plot for a contingency table
partition

Convert data-frame columns into Boolean or fuzzy predicates
var_names

Extract variable names from predicate names
which_antichain

Return indices of first elements of the list, which are incomparable with preceding elements.
dig_ancestors.associations

Dig ancestors of an association rule
association_matrix

Create an association matrix from a nugget of flavour associations.
dig_baseline_contrasts

Search for conditions that yield in statistically significant one-sample test in selected variables.
cluster_associations

Cluster association rules
add_interest.associations

Add additional interest measures for association rules
bound_range

Bound a range of numeric values
dig_associations

Search for association rules
dig_complement_contrasts

Search for conditions that provide significant differences in selected variables to the rest of the data table
dig

Search for patterns of a custom type
dig_correlations

Search for conditional correlations