# What is a minimal, reproducible example (reprex), and how do I write one?

I have been asked to write a minimal, reproducible example (reprex). What is that, and how do I write one?

## How to create a Minimal, Reproducible Example ("Reprex")

When asking a question that involves computer code, people will be better able to provide help if you provide code that they can easily understand and use to reproduce the problem. This is called creating a minimal, reproducible example (reprex); a minimal, complete, and verifiable example (mcve), or a minimal, workable example (mwe).

• ...Minimal: Use as little code as possible that still produces the same problem
• ...Complete: Provide all parts someone else needs to reproduce your problem in the question itself
• ...Reproducible: Test the code you're about to provide to make sure it reproduces the problem

The rest of this article provides guidance on these aspects of writing a minimal, reproducible example.

### Minimal

The more code there is to go through, the less likely people can find your problem. Streamline your example in one of two ways:

1. Restart from scratch. Create a new program, adding in only what is needed to see the problem. Use simple, descriptive names for functions and variables—don't copy the names you're using in your existing code.
2. Divide and conquer. If you're not sure what the source of the problem is, start removing code a bit at a time until the problem disappears—then add the last part back.

Don't sacrifice clarity for brevity when creating a minimal example. Use consistent naming and indentation, and include code comments if needed. Also, use spaces instead of tabs—tabs might not get correctly formatted on OR.SE.

### Complete

Make sure all information necessary to reproduce the problem is included in the question itself:

• If the problem requires both a model file and a data file, include code for both. The problem might not be in the file you think it is in. (Plus, we'll need both in order to run your code.)
• Use individual code blocks for each file or snippet you include. Provide a description for the purpose of each block.
• DO NOT use images of code. Copy the actual text from your code editor, paste it into the question, then format it as code. This helps others more easily read and test your code.

### Reproducible

The use of "reprex" for Reproducible Example was inspired by Jenny Bryan's reprex package for R.