Following up on my previous article about integrating large language models (LLMs) into R workflows, this piece dives deeper into generative AI tools designed to assist R programmers. These tools go beyond general-purpose AI and focus specifically on easing common coding challenges, whether you’re seeking interactive assistance or running local models. From enhancing your integrated development environment (IDE) to enabling local LLM interactions, R developers now have a growing toolkit tailored to their unique needs.
One of the primary ways R developers benefit from generative AI is through coding assistance. This includes autocompletion, refactoring, or getting help with writing unfamiliar functions. Whether you prefer staying inside your IDE or copying code into a separate interface, there are solutions for both. Tools like gander integrate directly with IDEs like RStudio and Positron, offering a more seamless, in-context experience when coding in R.
The gander package, for instance, acts like a lightweight, R-centric alternative to GitHub Copilot. Designed as an IDE add-in, gander is context-aware — it recognizes surrounding code and your current environment’s variables. When you highlight code and invoke the tool, you can choose whether the AI-generated output should replace the selection or appear before or after it. gander uses models supported by the ellmer package, and developer Simon Couch currently recommends Anthropic’s Claude Sonnet for its proficiency with R. You can easily set it as your default model with options(.gander_chat = ellmer::chat_claude())
.
To use gander, you’ll need to provide an API key for your selected LLM service. However, if you prefer not to rely on commercial APIs, you can run local models using ollama and still benefit from gander’s capabilities. Additionally, ellmer functions on its own as a chatbot interface for R-related queries, offering flexibility in how you interact with LLMs. For installation, gander is available on CRAN, or you can install the development version with pak::pak("simonpcouch/gander")
. This also sets up an RStudio add-in, and Positron users can configure gander through the command palette and keybindings.json
file, following instructions available on the package website.