Welcome to SO. In order to answer your question, please provide a minimal, complete, and verifiable example.
If you’ve ever asked a question on Stack Overflow (SO), you may recognize the quote above. This is because reproducibility is incredibly important when asking programming questions and it’s often overlooked. To be brief, a great reproducible example should be:
- Minimal – Provide the least amount of code needed to reproduce the problem.
- Complete – Provide everything needed to reproduce the problem (packages, data, functions, etc.).
- Verifiable – Test your code and confirm that it reproduces the problem.
Additionally, here’s a list of some other things I think are important:
- Load the packages you need. Don’t ask/answer questions with
library(tidyverse)when the user only needs
- Avoid text heavy questions. Questions are often easier to answer with just a few sentences, data, and the desired output.
- Ask one question at a time. If you have another, post a different question rather than modifying the original.
dputto copy/paste data and
reprexfor rendering your code.
- Avoid fragile and destructive code like
rm(list = ls()).