Skip to content
Prev 398350 / 398500 Next

Chatbot -generated R Code

A good summary. At the level of the summary it is not specific to R. However, asking a chatbot "I want a program to analyze my data" will not result in anything useful. You have to phrase the question to let the chatbot know what language, what does the data look like, and what do you want to do. So I might write: I have a data frame with three variables where V1 is time. I want an R program to calculate the mean of V3 for each unique value in V1. The answer will be R specific. The chatbot may guess at missing elements including generating fake data to act as an example. In "does the generated code work" the quality of the end result depends on the quality of the question asked. The chatbot works best with tightly focused simple questions. Complicated problems require complicated prompts and chatbots often ignore parts of long prompts. Developing good prompts is also a learned skill.

I would add
- is it worthwhile?

It takes time to write code. It also takes time to develop a good prompt. In both cases there will be a code validation and debugging step. What is the most efficient use of your time? What gives the best final product?

I might ask will you learn from it? The chatbot gave you an answer that you could not write yourself when you asked the chatbot. Given the chatbot answer do you understand it and could you now get that answer yourself?
The chatbot wrote: if(!require(tidyverse){install.packages('tidyverse')}
    And explained the solution. I understand, and this helps to avoid installing packages that are already installed. You can take it further and say: I have a program that requires 30 packages. In R, what is the shortest code that will check to see if they are already installed and to install ones that I do not have?

I get several answers, one of which is:
pkgs <- c("dplyr", "ggplot2", "lme4")
to_install <- pkgs[!pkgs %in% rownames(installed.packages())]
if (length(to_install)) install.packages(to_install)

I can then copy the code and ask the chatbot to explain the code, and progress from there.
If the chatbot is generating black boxes where "a miracle occurs" they will in the end cause you more problems than they solve. If all the code is generated by a chatbot and you do not understand it, what will you do when the boss stops by as asks for a modification or enhancement or a customer stops by and states that your code generates errors?

-----Original Message-----
From: R-help <r-help-bounces at r-project.org> On Behalf Of Richard O'Keefe
Sent: Tuesday, December 9, 2025 8:02 PM
To: Gregg Powell <g.a.powell at protonmail.com>
Cc: R help project <r-help at r-project.org>; Hans W <hwborchers at gmail.com>; Robert Knight <bobby.knight at gmail.com>
Subject: Re: [R] Chatbot -generated R Code

[External Email]

So to summarise, there are three key issues so dar:
- does the generated code work
- does it infringe on someone else?s intellectual property rights
- do the AI?s terms of service permit you to use it

What are some other things people who want to use an AI to generate code should consider?  Ither than the application domain,?is any of this specific to R?
On Wed, 10 Dec 2025 at 8:30?AM, Gregg Powell via R-help < r-help at r-project.org> wrote:

            
______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide https://www.r-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Message-ID: <CH3PR22MB45143110746733B67E1EAF37CFA0A@CH3PR22MB4514.namprd22.prod.outlook.com>
In-Reply-To: <CABcYAdKCe=n_+bMcHr0mV5JZcWq_9h5cbDCihpAuA83bkMK6Ew@mail.gmail.com>