How to R code faster with ChatGPT
Written by Matt Dancho

Writing code is a slow process especially when you are first learning data science. What if you could speed it up? You can and this is how. In this free R-tip, I share a real case study where I made the working R code for my data analysis in under 30 seconds with ChatGPT.
Table of Contents
Today I share how to automate R
coding with ChatGPT
. Here’s what you’re learning today:
- ChatGPT Prompts: The mistake you’ll make and how to get ChatGPT to write your code correctly.
- 2-Minute Case Study: How I connecte to an API, Downloaded Data, and Visualized on a Map with
ChatGPT
.
- Bonus: Sneak Peek At My NEW Shiny App that extends this ChatGPT tutorial

Inside the workshop I’ll share how to become exactly what companies need right now (and earn 17% more than a data scientist):

What: How To Become A 6-Figure Business Scientist (Even In A Recession)
When: Wednesday June 28th, 2pm EST
How It Will Help You: Data science in 2023 has changed. The 10+ person data science team is out. And the one-person Business Scientist is in. I’ll show you how to become a 1-person data science team inside my LIVE 6-figure business scientist masterclass.
Price: Does Free sound good?
How To Join: 👉 Register Here
R-Tips Weekly
This article is part of R-Tips Weekly, a weekly video tutorial that shows you step-by-step how to do common R coding tasks. Pretty cool, right?
Here are the links to get set up. 👇
This Tutorial is Available in Video
I have a companion video tutorial that walks you through how to use chatGPT
for this analysis. And, I’m finding that a lot of my students prefer the dialogue that goes along with coding. So check out this video to see me running the code in this tutorial. 👇
ChatGPT: And the Importance of Your Prompts
In my last R-Tip, I showed you how ChatGPT I made a full R Shiny App in under 10-minutes. That was insane!
But, after that R-tip, I felt a bit of a let down.
I began to try more and more complex stuff.
- I failed building high-end Shiny apps.
- I failed doing machine learning and integrating it into apps.
- And I got so frustrated that I even made a learning lab 82: ChatGPT for Data Scientists, where I showed every mistake I made in building a Production Shiny App (including the prompts, the 11 things I needed to fix in a live workshop, plus my debugging process).
But, now I’m 12 weeks into chatGPT
and I’ve realized 1 thing…
How important chatgpt
prompting is.
Take a look at this prompt. It’s just 2 sentences:

Looks fairly straightforward, but I need to show you why this prompt works (and what mistakes I was making in the last 11 weeks of using ChatGPT).
Chatgpt Prompt Guide (for R users)
The mistake I was making was not being specific enough in directing chatgpt
what R code I want it to write for me.
If you look at what I’m doing now…

…I specify:
- Which R Libraries <– always do this
- For this case study I want to know locations of all business types in a certain area:
- Which Business Types
- Which Geographic Location
And it generates the code for me:

Steal my code (it's legal).
Does the code work?
A big problem that data scientists are facing is that chatgpt
code isn’t working out of the box.
So let’s test the code. I ran it….

Steal my code (it's legal).
… And, it runs!
But, here’s the problem…
Will your ChatGPT code work?
The answer depends on how well you know the R ecosystem and can specify exactly what you want.
Question: Are you struggling with any of these tasks?
- Writing R code
- Doing business analysis
- Building solutions that company’s want
- Making a project portfolio for yourself
- Making solutions for your company
Then I have a free bonus:
Inside the workshop I’ll share how to become exactly what companies need right now (and earn 17% more than a data scientist):

What: How To Become A 6-Figure Business Scientist (Even In A Recession)
When: Wednesday June 28th, 2pm EST
How It Will Help You: Data science in 2023 has changed. The 10+ person data science team is out. And the one-person Business Scientist is in. I’ll show you how to become a 1-person data science team inside my LIVE 6-figure business scientist masterclass.
Price: Does Free sound good?
How To Join: 👉 Register Here
See you there!
-Matt Dancho