What is a reprex and why is it useful?


  • Applying some “code first aid” can help address problems in your code.Add commentMore actions
  • Helpers can more easily debug your code if you provide them with a small example of the problem (a “reprex”) that they can tinker with themselves.
  • In the process of building a reprex, you may find the solution yourself.
  • In the rest of this lesson, we will be working through a “road map” to getting unstuck that includes code first aid and the process of making a reprex.
  • The surveys dataset includes records of rodents captured in a variety of experimental plots over a 12-year period, including some data about each rodent’s sex and morphology.

Identify the problem and make a plan


  • The first step to getting unstuck is identifying a problem, isolating the problem area, and interpreting the problem
  • Often, using “code first aid” – acting on error messages, looking at data, inputs, etc., pulling up documentation, asking a search engine or LLM, can help us to quickly fix the error on our own.
  • If code first aid doesn’t work, we can ask for help and prepare a reproducible example (reprex) with a defined problem and isolated code
  • We’ll cover future steps to prepare a reproducible example (reprex) in future episodes.

Minimal reproducible codeMaking a reprex


  • Making a reprex is the next step after trying code first aid.
  • In order to make a good reprex, it is important to simplify your code
  • Simplify code by removing parts not directly related to the question
  • Give helpers access to the functions used in your code by loading all necessary packages

Minimal reproducible data


  • A minimal reproducible dataset (a) contains the minimum number of lines, variables, and categories, in the correct format, to replicate your problem; and (b) must be fully reproducible, meaning that someone else can run the same code from anywhere without additional steps.
  • To make it accessible, you can create a dataset from scratch using as.data.frame, you can use an R-built dataset like cars, or you can use a subset of your own dataset and then use dput() to generate reproducible code.

Asking your question


  • The reprex package makes it easy to format and share your reproducible examples.
  • The reprex package helps you test whether your reprex is reproducible, and also helps you prepare the reprex to share with others.
  • Following a certain set of steps will make your questions clearer and likelier to get answered.