Tools, sensitive data and sustainability. Applications in R
María Cristina Nanton
Developer
MinSal GCBA | The Global Health Network
Organizer at RLadies+ Buenos Aires
Contributor at RLadies+ Global
Data science in the public sector
Data-driven projects in a global health research network
There’s a new kind of coding I call “vibe coding”, where you fully give in to the vibes, embrace exponentials, and forget that the code even exists. […]
I “Accept All” always, I don’t read the diffs anymore. When I get error messages I just copy paste them in with no comment, usually that fixes it. […]
I’m building a project or webapp, but it’s not really coding - I just see stuff, say stuff, run stuff, and copy paste stuff, and it mostly works.
Andrej Karpathy, Twitter, February 2025 (emphasis mine)
If I don’t read the diffs anymore,
how do I know what it did is right?
And if the tool sees my whole project,
what is it seeing?
| What it does | Tool | What the model sees |
|---|---|---|
| Autocomplete | Copilot in RStudio | The open file |
| Talk to models from R | ellmer |
What you send it |
| Assistants in the editor | gander, chores |
The selection and your environment |
| Give the model your session | btw, mcptools |
Objects, docs, code running in your session |
| Agent in the terminal | Claude Code | The whole project |
The further down, the more autonomy and the more access.
gander, choresGitHub Copilot
Tools → Global Options → Copilot, enable it and connect your GitHub account
The comment works as a request; Tab accepts the suggestion.
gander
Select code, use a keyboard shortcut and ask for something like “plot this”. It looks at your objects, so it uses your real column names.
On RStudio Server or Workbench, Copilot only works if whoever runs the server enables it (copilot-enabled=1). Even here, the decision belongs to the organization.
ellmer: LLMs from RAn R package for using language models. Everything starts with a chat object, which keeps the conversation:
ellmer for analysts: from free text to dataClassify open-ended survey answers into categories:
library(ellmer)
# 1. The open-ended answers, as people wrote them
answers <- list(
"They took three hours to see me",
"The doctor explained everything very patiently"
)
# 2. What you want to get from each answer
categories <- type_object(
topic = type_enum(c("waiting", "treatment", "other")),
tone = type_enum(c("positive", "negative"))
)
# 3. Ask a model that runs on your machine
chat <- chat_ollama(model = "llama3.2")
parallel_chat_structured(chat, answers, type = categories)It returns a table with one row per answer and one column per category (topic, tone).
In 2023, ChatGPT made up more than half of the references it cited. With the same request, 2026 models hardly make any up, but some small models still do.
Queen, O. and Zou, J. (2026). The shelf life of LLM findings. Stanford University.
Walters, W. H. and Wilder, E. I. (2023). Fabrication and errors in the bibliographic citations generated by ChatGPT. Scientific Reports, 13, 14045.
Many of us who work in data analysis come from fields like sociology, psychology, political science or communication. We learned to program to answer questions, and few of us were taught to write tests.
A script that runs without errors can be computing something else:
join that duplicates rowsNAs dropped without warningPractices that help:
testthat tests on known casesrenv, Quarto, {targets}: to rerun the analysis and get the same resultBy all means, prompt AI. But don’t just relay the output. Read it, understand it, validate it, and then write a response in your own words (a decent certificate that you’ve done the prior steps). Making that effort is value you can add.
Niklas Gruhn, “Don’t be a meat proxy”, August 3, 2026
Tom Fishburne, “AI-Generated Homogeneity”, marketoonist.com
Before asking AI for something:
CLAUDE.md or AGENTS.md): data sources, history, caveats and decisions.Sharon Wang, “What context do your AI agents actually need?”, posit::conf 2026
In the cloud: Claude (Anthropic), ChatGPT (OpenAI), Gemini (Google), Copilot (Microsoft/GitHub)
Open models on your own infrastructure: Llama, Gemma, gpt-oss, Mistral, Qwen, DeepSeek, via Ollama or similar
To choose: cost, speed, hardware and privacy.
Based on L. D. Verde Arregoitia, LLMs in the R Space (R-Ladies Gaborone, 2025)
The regulatory floor
Your own floor
What data?
Confidential
.Renviron, in the code, in a screenshotInternal
Through where?
head(), glimpse(), an error that prints the row that failedEverything the model reads travels to the provider. In an R project, that can be head(patients), a readRDS("data/..."), the .Rhistory, rendered HTML with tables, the _freeze/ folder or an error that prints the row that failed.
The goal is for the model to see code, schemas and aggregate results, and never rows of data.
There are four layers for this, and each one covers what the previous one lets through:
CLAUDE.md. Easy to write, but the model may not follow them.If one layer fails, the next one stops it.
CLAUDE.md for an R project# Data privacy (mandatory)
## What you can see
- Code in R/, scripts/, tests/ and the .qmd files (without rendered outputs)
- The schema of each dataset: schemas/*.yaml
- Synthetic samples: samples/*.parquet (same structure, fake data)
- Aggregate reports: reports/*.json
## What you never do
- Don't read or print anything in data/. No head(), no glimpse(), no View().
- To answer questions about the data, write a script in scripts/tmp/
that returns ONLY aggregates with n >= 10. I run it and give you the result.
- In tests, use samples/, never real data.
## Why
This is patient data. Everything you read enters the context and leaves this machine.Explaining why helps the model comply. Still, with personal data, complying most of the time isn’t enough.
A list of files Claude Code can’t open with its reading tool. No programming needed.
But it only stops that tool. If Claude runs a terminal command that reads the file, the rule doesn’t see it:
cat data/discharges.csv
That’s what hooks are for.
A script that Claude Code runs before every terminal command (registered in the same .claude/settings.json). This one blocks any command that mentions data/ or .csv or .rds files.
# .claude/hooks/block_data.R
event <- jsonlite::fromJSON(file("stdin"))
cmd <- event$tool_input$command %||% ""
# does it mention the data folder or data files?
if (grepl("data/|\\.csv|\\.rds", cmd)) {
message("Blocked: ask for aggregates.")
quit(status = 2) # 2 = block
}
quit(status = 0) # 0 = let throughBut the hook only sees the command, not what the script it runs does:
Rscript scripts/tmp/peek.R
If peek.R opens the data and prints rows, it still gets through: the command doesn’t mention data/.
The agent works in a folder, a container or another machine where data/ doesn’t exist. To write correct code, the structure of the data is enough: a schema and a few synthetic rows (for example with {synthpop}).
The schema says which columns there are, of what type and in what range, without showing a single real value.
You ask for the script, telling it only which columns there are:
It returns something like this, which you run:
filter(n >= 10) is there because aggregates can also identify people: the mean of a group of one person is that person’s dataIndividual project, no sensitive data
CLAUDE.md, a settings.json and synthetic data take an afternoonOrganization with sensitive data
Any digital asset that affects people, projects or products in a research setting calls for assessing:
Where data is stored is a decision.
Is it your decision?
What value are we expected to bring
to the projects we work on?
What is worth investing time in?
R and LLMs
Data and evaluation
Thanks to Milagro Teruel for “Claude para ML sin ver los datos”, which inspired the part on working safely in an R project.
Generative AI and vibe coding in R&D · Versión en español