r2py: AI-Assisted Conversion of R Statistical Packages to Python
arXiv:2608.16911
Abstract
Thousands of R packages hold statistical methods with no native Python equivalent. Runtime bridges require an R installation; hand-written ports do not scale. Translation fails silently where the languages diverge, as in transform normalization, integer width, and argument evaluation. We present r2py, a framework that converts an R package into a native Python library using orchestrated language-model agents under human supervision, with correctness established by numerical comparison against the original at declared tolerances. The compiled code is retained unmodified, so any divergence lies in the translation. Seven phases decompose the work for independent invocations: structural analysis fixes conversion order, every base-R construct's rendering is settled in reviewable guides before code generation, and four verification methods each expose defects their predecessors miss. Packages reaching compiled code through .Call() add a five-phase prologue reconstructing the R C API they use. Conversions of KernSmooth and rpart reproduce R across 518 and 846 tests.
v2: substantially extended. Adds a second case study (rpart) reached through R's .Call() interface, and a five-phase prologue reconstructing the portion of R's C API the package uses so its original C compiles without R. v1 covered KernSmooth only. Title shortened