Home / Tools / Reprex Builder

Reprex Builder

A reprex is the minimal, self-contained R code someone needs to reproduce your problem on their own machine, and it is the first thing people ask for on Stack Overflow. Paste your messy code below: the builder hoists library() calls to the top, flags data it cannot find, pins the seed and wraps the result for wherever you are posting. Nothing leaves your browser.

Load a real-world example
Self-contained

Ready to paste

GitHub / Stack Overflow

      
Lines
0
Libraries
0
Blockers
0
Warnings
0
Notes
0

How this is built
1Every library() and require() call is moved to the top and de-duplicated, so a reader knows exactly what to install before running a single line.
2Each identifier is checked against base R, the common tidyverse verbs and the built-in datasets. Anything left over is flagged as data the reader will not have.
3Optional passes pin the seed, append sessionInfo() and re-prefix any console output you pasted as #> comments.
4The result is wrapped for the venue you picked. The wrapping and the #> prefix match the R reprex package exactly.
Capture real output in R with reprex

  

No data leaves your browser Venue formatting matches R's reprex package Free, no sign-up

The four things every reprex needs

A good reprex is minimal, self-contained, reproducible and clean. Miss one and the helper cannot run your code.

Libraries first

Every library() the code uses, moved to the top and trimmed of the ones it does not. The reader installs, then runs.

what to install
Inline data

No read.csv() and no reference to a saved object. Paste a tiny dput(head(df, 6)) instead, or use a built-in dataset.

self-contained data
Pinned randomness

Anything that draws random numbers gets a set.seed() before it, so the helper sees the same numbers you do.

same result every run

What the lints catch

LintWhat it meansThe fix
Undefined dataYou reference an object that is never created in the snippet, so the reader gets object not found.Paste dput() of a few rows, or switch to mtcars / iris.
File readFunctions like read.csv() point at a file only you have.Inline the data with dput() or use a built-in dataset.
Network callDownloads are slow and fail offline, so the reader may never reproduce it.Fetch once, keep the subset, paste its dput().
Missing seedRandom code with no set.seed() gives different numbers each run.Toggle Add set.seed(), or write one yourself.
Missing libraryTidyverse verbs appear but no library() loads the package.Add library(dplyr) / library(ggplot2) at the top.

When a reprex is the wrong tool

A code snippet cannot capture everything. If your bug needs the full pipeline to appear, bisect it by hand: cut half the steps and check whether it still fails. If the problem is an installation or platform issue, file the exact error, your sessionInfo() and your OS rather than a snippet. For a bug in interactive output such as RStudio panes or a Shiny widget, add a screenshot and the click sequence, and for Shiny share a self-contained app.R with a fake dataset. Never paste real or sensitive data; rebuild a synthetic frame with the same column names and types.

Reprex questions, answered

What is a reprex?

A reprex is a REProducible EXample: the smallest, self-contained snippet of R that anyone can paste into a fresh session and run end to end, without your data files, packages or working directory. It isolates the problem so a helper can focus on it instead of guessing at your setup.

Why do I need a reprex to get help on Stack Overflow?

Stack Overflow, GitHub issues and the R forums routinely close questions that lack a runnable example. A reprex turns a vague "this does not work" into a one-paste reproduction a stranger can confirm in seconds, which makes a good answer far more likely. You often solve your own problem halfway through writing one.

How is this different from the reprex R package?

The reprex package runs your code in a clean session and captures the real output. This builder does not run code; it cleans and lints your snippet in the browser, then shows the exact reprex::reprex() call to run for genuine captured output. Use the builder to prep and check, then run reprex for the final paste.

How do I share data without pasting a file?

Do not attach a CSV. In your real session run dput(head(your_data, 6)) and paste the output; it recreates a small copy of the data frame inline. For most bugs six rows are enough. If the bug only appears at scale, set a seed and simulate the smallest data that triggers it.

Does anything I paste get uploaded?

No. The builder runs entirely in your browser. Your code never leaves the page and nothing is sent to any server.

Keep going

The parser is a lightweight regex tokenizer, not a full R interpreter. It handles the common cases (library calls, assignments, file reads, plot calls, dataset references) but will not catch every edge case, so eyeball the output before you paste it into a question.