r2py: AI-Assisted Conversion of R Statistical Packages to Python
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.
Create a lesson
Related papers
QuantileMix: A Python package for quantile g-computation
Shared title terminology · Nilson Chapagain
Contrast-Aware Annotation for Statistical Graphics: The ggtwotone Package for ggplot2
Shared title terminology · Beenu Sareena, Heike Hofmann
Asgl: A Python Package for Penalized Linear and Quantile Regression
Shared title terminology · Álvaro Méndez Civieta, M. Carmen Aguilera-Morillo, Rosa E. Lillo
Eigen for Statistical and Machine Learning Computing: A Lightweight C++ Tutorial with Python Bindings
Shared title terminology · Seyoung Lee, Kwan-Young Bak
KernelMix: Bayesian kernel machine regression in Python
Shared title terminology · Nilson Chapagain
Deep Mixture Models: A Statistical Review with R
Shared title terminology · Jinran Wu, Geoffrey J. McLachlan