Large Language Model (LLM) agents can automate data-science workflows, but many rigorous statistical methods implemented in R remain underused because LLMs struggle with statistical knowledge and tool retrieval. Existing retrieval-augmented approaches focus on function-level semantics and ignore data distribution, producing suboptimal matches. We propose DARE (Distribution-Aware Retrieval Embedding), a lightweight, plug-and-play retrieval model that incorporates data distribution information into function representations for R package retrieval. Our main contributions are: (i) RPKB, a curated R Package Knowledge Base derived from 8,191 high-quality CRAN packages; (ii) DARE, an embedding model that fuses distributional features with function metadata to improve retrieval relevance; and (iii) RCodingAgent, an R-oriented LLM agent for reliable R code generation and a suite of statistical analysis tasks for systematically evaluating LLM agents in realistic analytical scenarios. Empirically, DARE achieves an NDCG at 10 of 93.47%, outperforming state-of-the-art open-source embedding models by up to 17% on package retrieval while using substantially fewer parameters. Integrating DARE into RCodingAgent yields significant gains on downstream analysis tasks. This work helps narrow the gap between LLM automation and the mature R statistical ecosystem.
翻译:大型语言模型(LLM)智能体能够自动化数据科学工作流程,但许多在R中实现的严谨统计方法仍未得到充分利用,因为LLM在统计知识和工具检索方面存在困难。现有的检索增强方法侧重于函数级语义而忽略数据分布,导致匹配效果欠佳。我们提出DARE(分布感知检索嵌入),一种轻量级即插即用的检索模型,将数据分布信息融入函数表示以实现R包检索。我们的主要贡献包括:(i)RPKB,一个从8,191个高质量CRAN包中构建的精选R包知识库;(ii)DARE,一种融合分布特征与函数元数据以提升检索相关性的嵌入模型;(iii)RCodingAgent,一个面向R的LLM智能体,用于可靠生成R代码,以及一套用于在真实分析场景中系统评估LLM智能体的统计分析任务。实验表明,DARE在NDCG@10指标上达到93.47%,在包检索任务中优于当前最优的开源嵌入模型达17%,同时参数量显著减少。将DARE集成到RCodingAgent中,在下游分析任务上取得了显著提升。这项工作有助于缩小LLM自动化与成熟的R统计生态系统之间的差距。