Skip to content
Join our email list to get $100 off Ally. The code expires October 31 →
R for the Rest of Us Logo

Ally Lesson Free

Write prompts that get good R code

This lesson is free.
Join Ally to see every lesson on using AI with R.

Join Ally

Transcript

Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.

I set out to make a lesson on writing prompts that get good R code, but I found that prompting matters less than it used to. When I tried to get Claude to give me base R code, it kept returning the tidyverse-style code I prefer, so this lesson ended up being about that and about the cases where prompting still helps.

You'll learn:

  • Why generic prompts like 'make me a bar chart in R' now tend to return ggplot2 code, including a possible explanation based on the amount of ggplot2 training data
  • How to prompt an AI agent to find base R code in an existing script and swap it for tidyverse-friendly alternatives
  • How to state a specific package preference, such as fs for files and directories, so the code matches your style
  • How standing instructions in a CLAUDE.md or AGENTS.md file can hold your coding preferences, such as the native pipe or ggplot2

Tools mentioned: Claude, ggplot2, tidyverse, fs, readr, CLAUDE.md, AGENTS.md

Key moments:

  • 00:00 Lesson turns out different than planned
  • 00:24 Livestream attempt to get base R code from Claude
  • 01:02 CSV reading and combining also comes back tidyverse
  • 01:18 LinkedIn replies from Jan and Gina Reynolds
  • 02:00 Prompting still helps for specific preferences
  • 02:34 Spotting base R dir.create in Claude's code
  • 02:50 Prompt to replace base R with tidyverse-friendly packages
  • 03:04 Claude swaps dir.create for fs::dir_create
  • 03:44 Other preferences and CLAUDE.md or AGENTS.md