DARE: Aligning LLM Agents with the R Statistical Ecosystem via Distribution-Aware Retrieval
Organizations: Department of Data Science and Artificial Intelligence, The Hong Kong Polytechnic University, Hong Kong SAR, China · Department of Applied Mathematics, The Hong Kong Polytechnic University, Hong Kong SAR, China.
Abstract
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.
Figures & tables
| Model | Params | NDCG@10 | MRR@10 | Recall@10 | Recall@1 |
| Snowflake/arctic-embed-l ( Merrick, 2024 ) | 335 M | 79.32% | 75.10% | 92.35% | 65.49% |
| Intfloat/e5-large-v2 ( Moreira et al., 2025 ) | 335 M | 75.13% | 70.86% | 88.38% | 61.52% |
| Jinaai/jina-embeddings-v2-base-en ( Günther et al., 2024 ) | 137 M | 74.29% | 69.65% | 88.73% | 59.69% |
| BAAI/bge-m3 ( Chen et al., 2024 ) | 568 M | 73.08% | 68.43% | 87.58% | 58.47% |
| Mixedbread-ai/mxbai-embed-large-v1 ( Lee et al., 2024 ) | 335 M | 70.68% | 65.65% | 86.39% | 55.08% |
| WhereIsAI/UAE-Large-V1 ( Li and Li, 2024 ) | 335 M | 70.66% | 65.56% | 86.58% | 54.79% |
| Model | RCodingAgent (w/o DARE) | RCodingAgent with DARE |
|---|---|---|
| Claude-haiku-4.5 | 6.25% | 56.25% |
| Deepseek-v3.2 | 18.75% | 56.25% |
| Gpt-5.2 | 25.00% | 62.50% |
| Grok-4.1-fast | 18.75% | 75.00% |
| Mimo-v2-flash | 12.50% | 62.50% |
| Minimax-m2.1 | 12.50% | 68.75% |
Appendix figures & tables3 assets
Supplementary material from the paper’s appendix.
Appendix
| Task Domain | Detailed Information |
|---|---|
| Independent component analysis | Package/Function: OPTICS K-Xi Density-Based Clustering::fortify_ica |
| Description: Density-based clustering utilities and visualization for ICA results | |
| Link: https://cran.r-project.org/web/packages/opticskxi/ vignettes/opticskxi.pdf | |
| Two-sample hypothesis test | Package/Function: Estimate a Log-Concave Probability Density from Iid Observations::logconTwoSample |
| Description: Two-sample hypothesis testing based on log-concave density estimation. | |
| Link: https://cran.r-project.org/web/packages/logcondens/logcondens.pdf |
Data Analysis Agents
Data analysis agents use language models and tools to explore datasets, run analyses, and produce answers or reports grounded in evidence.
See all 106 papers