Throughout this lesson, we will be walking through a “roadmap” to
getting unstuck in R by creating a minimal reproducible example
(“reprex”).
A reprex is a simplified version of your problematic code that
clearly demonstrates the problem you are facing and will run on anyone’s
computer.
A reprex should contain only the minimum required to replicate the
problem from any device so that helpers can more easily tinker and debug
your code.
The process of building a reprex helps you better understand your
code, your data, and your problem so that you will often find the
solution yourself!
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.
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.
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.