Reproducible Examples and the
reprex? Three common ways to use the term.
- noun, a reproducible example
reprexpackage. a tool to build R reprexes
reprex::reprex(), a function in
reprexto make a reprex.
- How do you actually get
reprexon your machine?
- Advanced setup and discussion.
- Please use advanced features responsibly.
Anyone who has helped teach R or dealt with github issues, twitter, stack overflow & RStudio community questions knows that helping people diagnose their coding problems can be hard.
This tool comes from hard-won experience. Its aim to is help people ask well formed questions and increase the chances of getting well formed answers quickly.
Code that I don't need to run -
reprexgives your reader the code and reveals the output being produced by that code. For experienced coders, that might be enough to help you.
Code that I can easily run - Don't copy and paste from the R console. This is usually annoying for your reader. Worse than console copy-pasta is the screenshot. (Many people think screenshots of code are downright offensive.)
reprex_clean- If you copy someone else's reprex into your console, it may include their output, making your new reprex untidy. Here are tips for taking someone else's
reprexcode and output, and creating a clean
Shock and Awe: Additional interesting features of the
Differently flavored markdown. Optimize your
reprexmarkdown output for GitHub, Stack Overflow, or the RStudio Community.
Make your reprex create an R script, with your reprex outputs as comments. This is handy for pasting into an email or slack-type-app.
Rich text (.rtf) output. (currently an experimental feature as of this video)
Auto styling of your code. Good if you're dealing with poorly formatted code.
Capture a reprex that sends messages to standard output and standard input (e.g. package installation compilation messages).
- "render reprex" and "reprex selection". These accelerate your use of
How to ask questions in ways that are most likely to get answered.
Sorry for the tough love, but this is important. Why are you always asked to give a reprex?
- Experts try to use reproducible examples to ensure their advice works.
- Making a good reprex is hard. But, you are asking them to solve a problem for you, so meet them halfway.
- Creating reprexes is good coding practice.
- Making a good reprex is often a good way to debug your issue in the embarrassment-free privacy of your own home.
- reprexes lead to discussions more likely to help people in the future.
Questions and Answers
reprexcapture variables and objects in the current environment? (not yet, maybe in development)
reprexactually check that the code is self-contained?
readr::read_csvsupport the text argument? (yep, just read the help manual for readr)