
A complete toolkit for connecting R and LLMs
btw helps R users work with Large Language Models, whether you’repasting context into ChatGPT, chatting with an AI assistant in your IDE,or building LLM-powered applications.
The challenge: LLMs need context about your R environment to behelpful—your data structures, the packages you’re using, relevantdocumentation.
btw provides a flexible toolkit that works across differentworkflows:
Usebtw() to gather context from your R session and copyit to your clipboard:
library(btw)# Describe a data framebtw(mtcars)# Include package or function documentationbtw("{dplyr}", ?dplyr::across)# Combine multiple pieces of contextbtw(mtcars,"{dplyr}","How do I calculate the mean mpg by cylinder?")The context is copied to your clipboard, ready to paste into ChatGPT,Claude, or any LLM chat interface.
Launch a chat interface withbtw_app():
btw_app()
For persistent project context, create abtw.md filewithuse_btw_md(). This creates a project-specificconfiguration file where you can define your preferred LLM provider,model, and custom instructions that apply to all conversations in yourproject.
btw superchargesellmer!Usebtw_client() for a pre-configured chat client, the sameclient used bybtw_app().
# Uses provider, model, tools and instructions from btw.mdchat<-btw_client()chat$chat("Help me write documentation for...")Or usebtw_tools() to get a list of tools you canregister with any ellmer chat client.
library(ellmer)chat<-chat_anthropic()# or chat_openai(), chat_ollama(), etc.chat$register_tools(btw_tools())chat$chat("What data frames are in my environment?")Pick and choose which tools you use with friendly group names
# Only provide documentation and file toolschat$register_tools(btw_tools(c("docs","files")))or expose btw tools to external coding agents via theModel Context Protocolusingmcptools.
# Run as a background process or in a separate R sessionbtw_mcp_server()You canconfigure theMCP server in Claude Desktop, Continue, or other MCP-compatibletools to give them access to your R environment.
You can install btw from CRAN:
install.packages("btw")To install the latest development version, you can install fromposit-dev.r-universe.dev:
# install.packages("pak")pak::repo_add("https://posit-dev.r-universe.dev")pak::pak("btw")Or you can install the development version fromGitHub:
# install.packages("pak")pak::pak("posit-dev/btw")For questions or issues, pleaseopen an issue onGitHub.