LLMs in R for Data Analysis

rainbowR Conference Workshop

by Nic Crane

Wednesday 25th February 2026, 19:00-21:00 UTC / 14:00-16:00 ET / 11:00-13:00 PT


Workshop Overview

LLMs can be massively useful in R workflows, when used in the right places and if you’re aware of not only the benefits, but also the risks. In this hands-on workshop, you’ll learn how to use LLMs programmatically in R, and come away with both the confidence to experiment and a working script that extracts data from unstructured text.

We’ll look at where LLMs can help, where they’ll let you down, and techniques for making your results more trustworthy. You’re going to leave with a practical sense of what’s possible and where to be cautious.

What you’ll learn:

  • Getting started with LLMs in R using {ellmer}
  • Prompt engineering for more predictable results
  • Extracting structured data from unstructured text
  • Using LLMs to call R functions (tool calling)

Workshop Prework

Environment

You’ll need an R environment to work in; this could be RStudio or Positron on your own laptop, or an account on Posit Cloud via a web browser.

If you’re on a work machine with restrictions on installing software or connecting to external APIs, Posit Cloud is a good option as everything runs in your browser.

Packages

Install the required packages:

install.packages(c("ellmer", "mall", "dplyr", "readr", "tidyr", "usethis"))

API keys

You’ll need an API key from an LLM provider. We recommend Gemini (free), but Anthropic or OpenAI work too if you already have credits.

Option 1: Gemini (free)

  1. Go to Google AI Studio
  2. Sign in with your Google account
  3. Click “Create API key”
  4. Copy the key

Option 2: Anthropic or OpenAI (paid)

If you already have an Anthropic or OpenAI account with credits, you can use that instead.

Once you have your key, run usethis::edit_r_environ() and save the key as:

GOOGLE_API_KEY=your-key-here
# OR
ANTHROPIC_API_KEY=your-key-here
# OR
OPENAI_API_KEY=your-key-here

You will need to restart your R session after saving the environment variable.

Test setup

After installing packages and setting up your API key, verify everything works:

library(ellmer)

# Test API connection (restart R first if you just set the key!)
chat <- chat_google_gemini()  # or chat_anthropic() / chat_openai()
chat$chat("Say hello in one sentence")

If you see a response from the LLM, you’re all set!

Workshop Schedule

  • Section 0: Welcome and Setup
  • Section 1: Getting Started with LLMs in R
  • Section 2: Prompt Engineering
  • Section 3: Structured Output
  • Section 4: Tool Calling
  • Section 5: Wrap-up and Resources

Instructor

Nic Crane is an R consultant with a background in data science and software engineering. They are passionate about open source, and learning and teaching all things R.


Copyright © 2025 Nic Crane. All Rights Reserved.