arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2608.16911stat.COcs.PL

r2py:用于AI辅助将R统计包转换为Python的框架

r2py: AI-Assisted Conversion of R Statistical Packages to Python

Yufei Cai, Jun Li

首次发表
浏览论文内容

中文总结 AI 辅助

本文提出r2py,这是Claude Code环境中首个七阶段AI辅助方法,可将R包系统转换为数值保真的原生Python库,在KernSmooth包上实现的r2py_kernsmooth通过518项测试,有效数字一致性达6-10位。

中文摘要 AI 辅助

R统计计算环境拥有大量经过验证、高性能的统计包实现,这些实现无法作为原生Python库使用。手动转换这些包既耗时、易出错且难以规模化,而rpy2和reticulate等运行时桥接解决方案需要安装R并引入进程间开销。大语言模型(LLM)提供了自动化途径,但无指导的统计代码转换会因R与Python之间的语义差异产生隐蔽的数值误差,仅通过源代码检查无法明显察觉。本文提出r2py,这是一种七阶段的AI辅助方法,用于系统、可复现地将R包转换为Python,在Claude Code智能体开发环境中实现为编排技能(顶层斜杠命令)和专用子智能体的结构化层级。据我们所知,r2py是首个用于LLM辅助将R包转换为原生、数值保真Python库的系统方法。该方法系统地解决每类转换误差源:它编目所有特定语言的调用点,在编写任何代码前生成专用的机器可读转换指南;按拓扑依赖顺序转换函数;并以指定容差对输出与实时R实现进行数值验证。我们在KernSmooth(v.2.23-26,一款实现核平滑方法的推荐R包)上演示了该框架。生成的Python包r2py_kernsmooth在Python 3.14下通过了针对R参考的518项断言测试,所有七个公开函数均达到6至10位有效数字的一致性。

英文摘要

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.

补充信息

↑