Questions, Source Code, and Debugging

2026-01-27

1 Asking Good Questions

Good questions:

  • are easy for the person to answer

  • get you the information you’re asking for

2 Strategies for Asking Good Questions

  • State what you know.
  • Guess what the answer might be.
  • Choose who to ask. (The person who knows the most isn’t always the best person to ask! Often someone who learned it more recently will remember better what it was like to not understand.)
  • Find a good time.
  • Do some research (“If I spend some time doing research first, I can ask a way better question.”)
  • Ask yes/no questions.

3 Practice: How to make a reprex

What is a reprex? It’s a reproducible example, as coined by Romain Francois in a tweet from 2014.

  1. Copy code
  2. Run reprex()
  3. Admire, locally.
  4. Paste into target.
  5. Wait for help.

4 When to make a reprex?

  1. Seek help on Posit Community
  2. Asking questions on Stack Overflow
  3. Report a bug (or start a discussion) on GitHub.
  4. Talk about R in a message or email to a friend or colleague.

5 Why make a reprex?

Conversations about code are more productive with:

  1. Code that actually runs
  2. Code that I don’t have to run.
  3. Code that I can easily run.

6 Code that actually runs

Code is run in a new R session So, it must be self-contained.

  • You must load the required packages.
  • You must create all required objects.

7 Code that actually runs

Use the smallest, simplest, most built-in data possible.

Standard tricks for the inline creation of a small data frame.

8 Code that I don’t have to run

Many readers… can often get the point w/o running code, especially if they can see the output.

9 Code that I can easily run

  • do not copy/paste from the R console (it takes fiddly edits to reproduce)

  • do not take a screenshot of your R session (it takes re-typing everything to reproduce)

10 Why make a reprex?

How you ever helped a relative with a computer problem?

That is how it feels to answer a programming question based on a prose narrative.

11 Do you have to make a reprex?

“Making a good reprex is a lot of work!”

Yes! You are asking other people to experience your pain. Meet them halfway.

12 Do you have to make a reprex?

Making a good reprex often leads to solving your own problem. In private.

13 Read the Source Code

  • Search for the error message
  • Read the whole thing
  • Edit the code

14 Debugging

“Love Your Bugs”

  • Debugging is a great way to learn.
  • Fixing bugs is also a good way to learn to write more reliable code.
  • Nobody writes great code without writing and fixing lots of bugs.

15 How I got better at debugging

  • Remember the bug is happening for a logical reason.
  • Be confident I can fix it.
  • Talk to my co-workers.
  • Know my debugging toolkit.
  • Most importantly: I learned to like it.

16 Resources: Debugging with R

17 Resources: Debugging Quarto