gander is a higher-performance and lower-friction chat experience for data scientists in RStudio and Positron–sort of like completions with Copilot, but it knows how to talk to the objects in your R environment. The package bringsellmer chats into your project sessions, automatically incorporating relevant context and streaming their responses directly into your documents.
Why not just chat? In many ways, working with gander is just like using a chat interface online or viashinychat. The gander assistant will automatically find the context it needs, though:
- Code context: File contents from elsewhere in the project you’re working on (e.g. the lines in your source file).
- Environment context: Variables, allowing the assistant to locate the column names and types in data frames you’re working with, images linked to in your documents, and function definitions. This is what differentiates gander from many other assistants out there; gander can interface with your R session to describe your computational environment.
Important
For now, gander is particularly effective in
.Rfiles but struggles to provide appropriately formatted responses in.Qmdand related file formats.
Installation
You can install gander like so:
install.packages("gander")To install the developmental version:
pak::pak("simonpcouch/gander")Then, you’ll need to hook gander up with anellmer chat. gander uses the.gander_chat option to configure which model powers the addin; just set the option to whatever your usual ellmer setup is. For example, we recommend Anthropic’s Claude Sonnet 3.7, which you can use viaoptions(.gander_chat = ellmer::chat_anthropic()) once you’ve configured anANTHROPIC_API_KEY. Paste that code in your.Rprofile viausethis::edit_r_profile() to always use the same model every time you start an R session. gander supports any model supported by ellmer, so you can use Anthropic’s Claude, OpenAI’s GPT-4o, local ollama models, etc. See “Choosing a model” invignette("gander", package = "gander") to learn more.
The gander assistant is interfaced with the via the gander addin. For easiest access, we recommend registering the gander addin to a keyboard shortcut.
In RStudio, navigate toTools > Modify Keyboard Shortcuts > Search "gander"—we suggestCtrl+Alt+G (orCtrl+Cmd+G on macOS).
In Positron, you’ll need to open the command palette, run “Open Keyboard Shortcuts (JSON)”, and paste the following into yourkeybindings.json:
{"key":"Ctrl+Cmd+G","command":"workbench.action.executeCode.console","when":"editorTextFocus","args":{"langId":"r","code":"gander::gander_addin()","focus":true}}The analogous keybinding on non-macOS isCtrl+Alt+G. That said, change the"key" entry to any keybinding you wish!
Once those steps are completed, you’re ready to use the gander assistant with a keyboard shortcut.
Example
This screencast demonstrates using the gander addin to iterate on a plot:
After loading the stackoverflow data into my environment, I highlightstackoverflow and type a plain language request to plot the data. The LLM’s response—which provides a minimal solution and refers to correct column names—is streamed directly into my document and selected in whole. After visually inspecting, I run the code, and then retrigger the addin and type a followup request to refine the plot, doing so iteratively until I’m satisfied with my results.
To read more about using the addin, check out the Getting Started vignette withvignette("gander", package = "gander").
