Learn Data Science for Business
Become a Data Scientist in our online courses
Earn 6 figures or more in 6 months or less by learning R, Shiny, Machine Learning, Time Series, Web Apps, AWS, Cloud, and more!
5-10 Hours Per Week. 80/20 Skills. End-To-End Business Projects.
Join over 100,000+ Data Scientists
How to Get ChatGPT in R with chattr
Written by Matt Dancho
Hey guys, welcome back to my R-tips newsletter. ChatGPT is a massive productivity enhancer. Lately it’s felt like VSCode, which integrates AI via GitHub Copilot, is moving faster than the RStudio IDE when it comes to integrating AI. Fortunately, I stumbled upon a new R package that integrates ChatGPT in R via RStudio IDE. It’s called chattr, and I’m sharing how to get started in under 5 minutes. Let’s go!
Table of Contents
Here’s what you’re learning today:
- What is chattr? You’ll discover what
chattris and how it brings LLMs to RStudio - Benefits of using Chattr How
chattrprovides additional context to OpenAI ChatGPT and GitHub Copilot LLMs from inside RStudio - How to get ChatGPT inside of RStudio You’ll install
chattrand set up ChatGPT inside of Rstudio - Make a quick Shiny App with chattr I’ll explain how to make your first shiny app to explore your dataset.
Get the Code (In the R-Tip 080 Folder)
SPECIAL ANNOUNCEMENT: AI for Data Scientists Workshop on December 18th
What: GenAI for Data Scientists
When: Wednesday December 18th, 2pm EST
How It Will Help You: Whether you are new to data science or are an expert, Generative AI is changing the game. There’s a ton of hype. But how can Generative AI actually help you become a better data scientist and help you stand out in your career? I’ll show you inside my free Generative AI for Data Scientists workshop.
Price: Does Free sound good?
How To Join: 👉 Register Here
What is chattr
chattr is an interface to LLMs (Large Language Models). It enables interaction with the model directly from the RStudio IDE. chattr allows you to submit a prompt to the LLM from your script, or by using the provided Shiny Gadget.
Chattr provides integration to many common models including OpenAI’s GPT models, Llama, and GitHub Copilot:
Once set up, you can use an LLM widget inside of RStudio IDE:
Benefits of using Chattr: Knowledge of Your RStudio Environment
chattr enriches your request with additional instructions, name and structure of data frames currently in your environment, the path for the data files in your working directory. If supported by the model, chattr will include the current chat history.
Tutorial: How to get ChatGPT inside of RStudio
It takes about 1 minute to get chattr set up so you can start using ChatGPT inside of Rstudio. All the tutorial code shown is available in the R-Tips Newsletter folder for R-Tip 080.
Here’s how to set up Chattr:
Follow these 5 steps:
- Install:
chattris not on CRAN as of this article. But you can install from GitHub. - Load: Load
chattr - API Key: Set up your OpenAI API Key.
- Select a Model: For this demo I’m using gpt-3.5-turbo, denoted “gpt35”. But you can use gpt-4-turbo as well with “gpt4”.
- Run Chattr: This fires up a
chattr_app()as a background job.
Success: A ChatBot Just Appeared inside Rstudio
Once successful you’ll see a dialog open in the RStudio Viewer window. You can begin asking questions like how to read the data from the chattr folder.
Chattr Background job
One thing I want to mention is why it makes sense to run Chattr as a background job. Running as a background job frees up your Console so you can continue to work.
Make a quick Shiny App with chattr
One of the things I love LLM’s for is building shiny apps. So I’ll share a quick dialog I had with chattr to make one. The chattr shiny app is in the test_shiny_app.R file.
One of the things I wanted to do was explore a Marketing Campaign dataset that I have inside the R-Tip 80 folder marketing_campaign.csv.
So I asked it how to make a minimal shiny app to explore the data?
And it made this for me (shiny app is in the R-Tip 80 Folder):
Conclusions:
This is exciting! Chattr is making it easier and more productive for me to use LLM’s in my R workflow. I look forward to seeing how chattr progresses as LLM’s become a bigger part of my data science process.