Automatically Reduce Failing R Scripts to a Minimal Reproducible Example

Shrinks a failing R script to the smallest subset of statements that still triggers the same error, using the delta debugging algorithm of Zeller and Hildebrandt (2002) . Each candidate reduction is evaluated in a separate R process, so dependencies between statements and their side effects are respected. The result is a one-minimal example, in which removing any remaining statement makes the error disappear; this is the form most useful for bug reports and for questions on community forums. When no statement can be removed, because the failure is nested inside a function body, reduction continues within the surviving statements. A general delta debugging routine and a helper for reducing data frames to the rows that reproduce a failure are also provided.


minex

Lifecycle:experimental R-CMD-check

reprex makes your bug reproducible. minex makes it minimal.

When you ask for help with R, you are told to post a minimal reproducible example. The reprex package runs and formats your code; it does not shrink it. minex shrinks it: paste in a failing script and it returns the smallest subset of statements that still throws the same error, finding it by delta debugging rather than by deleting lines and re-running by hand.

Installation

# install.packages("pak")
pak::pak("DIGlabUAB/minex")

Usage

library(minex)

script <- c(
  "a <- 10",
  "b <- 20",
  "log('not a number')"
)

minex(code = script)
#> <minex_result> 3 statement(s) reduced to 1 (3 oracle call(s))
#> target failure: non-numeric argument to mathematical function
#> ------------------------------------------------
#> log('not a number')

The setup lines are dropped and only the offending statement remains. A statement that the failure genuinely depends on is kept, because removing it changes the error and the reduction is rejected.

minex() also reads a file directly:

minex(file = "analysis.R")

And reduce_rows() does the same job for a data frame, returning the rows that still reproduce a failure:

df <- data.frame(id = 1:6, value = c(3, 8, 999, 2, 5, 7))
reduce_rows(df, function(d) any(d$value > 100))
#>   id value
#> 3  3   999

How it works

Each candidate reduction runs in a fresh R process (via callr) so that statement dependencies and side effects are respected. A candidate “reproduces” the failure when it errors with the same message as the original; matching on the condition class instead, or supplying a custom oracle, is also supported. The engine is ddmin(), an implementation of the delta debugging algorithm of Zeller and Hildebrandt (2002), exposed for reuse on any collection.

See vignette("minex") for the full walkthrough.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("minex")

0.2.0 by Sumanth Chandrupatla, 2 months ago


https://github.com/DIGlabUAB/minex


Report a bug at https://github.com/DIGlabUAB/minex/issues


Browse source code at https://github.com/cran/minex


Authors: Sandeep Bodduluri [aut, cph] (ORCID: , Sumanth Chandrupatla [aut, cre, cph] (ORCID:


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports callr, stats, utils

Suggests clipr, ellmer, knitr, rmarkdown, spelling, testthat


See at CRAN