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 connect 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

SPECIAL ANNOUNCEMENT: ChatGPT for Data Scientists Workshop on October 18th
Inside the workshop I’ll share how I built a Machine Learning Powered Production Shiny App with ChatGPT
(extends this data analysis to an insane production app):

What: ChatGPT for Data Scientists
When: Wednesday October 18th, 2pm EST
How It Will Help You: Whether you are new to data science or are an expert, ChatGPT is changing the game. There’s a ton of hype. But how can ChatGPT actually help you become a better data scientist and help you stand out in your career? I’ll show you inside my free chatgpt for data scientists workshop.
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.
Struggling to become a data scientist?
You know the feeling. Being unhappy with your current job.
Promotions aren’t happening. You’re stuck. Feeling Hopeless. Confused…
And you’re praying that the next job interview will go better than the last 12…
… But you know it won’t. Not unless you take control of your career.
The good news is…
I Can Help You Speed It Up.
I’ve helped 6,107+ students learn data science for business from an elite business consultant’s perspective.
I’ve worked with Fortune 500 companies like S&P Global, Apple, MRM McCann, and more.
And I built a training program that gets my students life-changing data science careers (don’t believe me? see my testimonials here):
6-Figure Data Science Job at CVS Health ($125K)
Senior VP Of Analytics At JP Morgan ($200K)
50%+ Raises & Promotions ($150K)
Lead Data Scientist at Northwestern Mutual ($175K)
2X-ed Salary (From $60K to $120K)
2 Competing ML Job Offers ($150K)
Promotion to Lead Data Scientist ($175K)
Data Scientist Job at Verizon ($125K+)
Data Scientist Job at CitiBank ($100K + Bonus)
Whenever you are ready, here’s the system they are taking:
Here’s the system that has gotten aspiring data scientists, career transitioners, and life long learners data science jobs and promotions…

Join My 5-Course R-Track Program
(And Become The Data Scientist You Were Meant To Be...)
P.S. - Samantha landed her NEW Data Science R Developer job at CVS Health (Fortune 500). This could be you.
