MacMusic  |  PcMusic  |  440 Software  |  440 Forums  |  440TV  |  Zicos
gander
Recherche

GenAI tools for R: New tools to make R programming easier

mardi 25 mars 2025, 10:00 , par InfoWorld
GenAI tools for R: New tools to make R programming easier
My previous article focused on some of the best tools for incorporating LLMs into your R scripts and workflows. We’ll expand on that theme here, offering up a collection of generative AI tools you can use to get help with your R programming or to run LLMs locally with R.

Coding help for R developers

Getting help with writing code is one of the most popular uses for large language models. Some developers prefer to use these tools within their integrated development environments (IDEs); others are content to copy and paste into external tools. R programmers have options for both.

gander

The gander package is a bit like GitHub Copilot Light for R scripts. It’s an IDE add-in for RStudio and Positron that can be aware of code in scripts around it as well as variables in your working environment. If you’ve selected code when you invoke gander, you’ll be asked whether you want the model’s result to replace that code or be added either before or after.

gander’s interface asks if you want to replace selected code or put its suggestions either before or after your selection.

You can choose any model supported by ellmer to use in gander. As of early 2025, package author and Posit developer Simon Couch recommended Anthropic’s Claude Sonnet for its R prowess. You can set that as your default with options(.gander_chat = ellmer::chat_claude()).

As always when using a commercial LLM provider, you need to make an API key available in your working environment. As with many current R packages for working with LLMs, you can also use a local model powered by ollama. Note that you can also use ellmer as a chatbot to ask questions about R and run LLMs locally. (See my previous article for more about ellmer and ollama.)

Installing gander

gander is available for R scripts in both RStudio and Positron. You can download it from CRAN or install the development version with pak::pak('simonpcouch/gander').

That command also installs an add-in within RStudio, where you can choose a keyboard shortcut to invoke it.

For Positron, there are instructions on the package website’s homepage for opening the Positron command palette and adding code to the keybindings.json file.

To see what data gander sent to the model—the background information from your script and working session, as well as the question you typed—you can run gander_peek() after running the add-in.

Some gander settings can be changed with R’s options() function. The tool’s default style instructions are:

Use tidyverse style and, when relevant, tidyverse packages. For example, when asked to plot something, use ggplot2, or when asked to transform data, using dplyr and/or tidyr unless explicitly instructed otherwise.

You can change that default with code such as options(.gander_style = 'Use base R when possible.') See more customization possibilities by running?gander_options in your R console.

You can learn more about gander on the gander package website and Posit blog.

chatgpt

An “interface to ChatGPT from R,” chatgpt features around 10 RStudio add-ins for things such as opening an interactive chat session, commenting selected code, creating unit tests, documenting code, and optimizing selected code. If you don’t select any code for the programming-specific tasks, it will evaluate the entire active file.

This could be a good choice for people who don’t use large language models often or don’t want to write their own prompts for regular programming tasks. And if you don’t want to call on different add-ins for each task, you can use its functions in the terminal, such as comment_code() and complete_code().

You can customize model settings with R environment variables, such as OPENAI_MODEL (gpt-4o-mini is the default), OPENAI_TEMPERATURE (which defaults to 1—my choice would be 0), and OPENAI_MAX_TOKENS (which defaults to 256).

Note that the chatgpt package only supports OpenAI models.

gptstudio

gptstudio, on CRAN, is another RStudio add-in that offers access to LLMs. It features defined options for spelling and grammar, chat, and code commenting. I found the interface a bit more disruptive than some other options, but opinions will likely vary on that.

The gptstudio package supports HuggingFace, Ollama, Anthropic, Perplexity, Google, Azure, and Cohere along with OpenAI.

pkgprompt

pkgprompt can turn an R package’s documentation—all of it or only specific topics—into a single character string using the pkg_prompt() function. This makes it easy to send that documentation to an LLM as part of a prompt. For example, the command

library(pkgprompt)pkg_docs
https://www.infoworld.com/article/3848270/genai-tools-for-r-new-tools-to-make-r-programming-easier.h

Voir aussi

News copyright owned by their original publishers | Copyright © 2004 - 2025 Zicos / 440Network
Date Actuelle
mer. 26 mars - 04:39 CET