library(querychat)
library(readr)
library(here)
# one row per laureate per prize, cleaned from the Nobel Prize API
nobel <- read_csv(here("data/nobel.csv"), show_col_types = FALSE)
querychat_app(
nobel,
table_name = "nobel",
client = "anthropic/claude-sonnet-5-5",
# context for the LLM: what the columns mean and how to use them
data_description = here("data/nobel-description.md"),
# shown when the app opens; no LLM call needed
greeting = here("data/greeting.md"),
# ggsql 0.5.2 draws empty bars when x is numeric, so ask for text instead
extra_instructions = "In bar charts, cast a numeric x variable such as a year or decade to VARCHAR."
)
# 1. Ask one question of each kind:
# - Filter: "Show only laureates in Physics since 2000"
# - Summarize: "Who was the youngest laureate in each category?"
# - Visualize: "Plot the share of female laureates by decade"
# Open the tool card under each answer. Which tool was called? What
# programming language did it write?
#
# 2. Type /handoff. Select the results you want to keep, choose Quarto, and
# download the bundle. Unzip it, open the .qmd, and render it.
# Do the numbers and charts match what you saw in the chat?Exploring Nobel laureates with generative AI
Application exercise
Exercise 01
data/nobel-laureates.json is the raw response from the Nobel Prize API. It has every laureate from 1901 to 2026, with all of their prizes.
Use Posit Assistant to turn it into a tidy data frame, explore it, and write up what you find. Some places to start:
- “Load
data/nobel-laureates.jsonand describe its structure.” -
/cleanto enter cleaning mode - “What patterns should I look at next?”
-
/reportto save your analysis as a Quarto document
As you go, keep track of two things.
- Two or three insights you’d share with someone who knows nothing about the data.
- The decisions made along the way. What got kept, dropped, recoded, or summarized? Who made each call, you or the assistant?
You’ll compare notes with a classmate when time is up.
Exercise 02
Acknowledgments
- Nobel Prize data from the Nobel Prize API.