ChatGPT can answer questions about a wide range of technology subjects, including how to write R code. That means ChatGPT’s power is available to every R programmer, even those who know little about large language models.
An ecosystem is forming around ChatGPT and R, making it easy to incorporate AI technology into your R language workflow. But before you begin using LLMs and related tools for your R projects, there are a few important things to keep in mind:
Everything you ask using these tools gets sent to OpenAI’s servers. Don’t use ChatGPT tools to process sensitive information.
ChatGPT may confidently return incorrect answers. Even incorrect responses can be a starting point, and save you time, but don’t assume the code will do exactly what you expect. Kyle Walker (an associate professor at Texas Christian University and author of the popular tidycensus R package) tweeted that ChatGPT can “supercharge your work if you understand a topic well,” or it can leave you “exposed for not knowing what you are doing.” The difference is in knowing when the AI output isn’t right. Always check ChatGPT’s responses.
ChatGPT can also generate different responses to the same query—and some answers might be accurate while others aren’t. For instance, when I asked multiple times for a ggplot2 bar chart with blue bars, the code generated a graph with blue bars sometimes but not others, even though I submitted the same request each time. This is less than ideal if you need a reproducible workflow.
LLMs have training data cutoff dates, so if there’s been a recent update to a package you’re using, your tool of choice may not know about it.
Most of the resources in this article require you to have your own OpenAI API key, and the API isn’t free to use. While pricing is low at the moment, especially for GPT-3.5, there’s no guarantee it will stay that way.
Asking ChatGPT for coding help is unlikely to ensnare you in the ethics of AI racial and gender bias. However, there are heated discussions about the wisdom of furnishing OpenAI with yet more data; the ethics of how the training data was scraped and repurposed; and whether it’s better to use open source LLMs (such as Mistral’s) rather than OpenAI’s. Those dilemmas are for every individual and organization to wrangle for themselves. However, as of this writing, there simply aren’t R-specific LLM tools that are comparable to those building up around ChatGPT.
Now, let’s look at some of the most notable R-focused resources for using OpenAI’s GPT-3.5 and GPT-4 LLMs.