10  Troubleshooting

It is normal to have errors when working with R and quarto. Problems can be minimised by developing the document and code incrementally and rendering it repeatedly so that errors can be detected immediately.

10.1 Common issues

10.1.1 Duplicate block labels

Code block labels must be unique. If they are not you will get an error message including the following

  Duplicate chunk label 'import', which has been used for the chunk:

Identify the offending code block and re-label it.

10.1.2 More errors to come

Tell me what you find difficult.

10.2 Solving problems

10.2.1 Interpret error messages

If you get an error message, read it and try to understand it. Copy it and paste into Google (or similar), someone has probably had the same problem before and there may be a solution at stackoverflow.com or elsewhere.

10.2.2 Make a minimal, reproducible example

A minimal, reproducible example or (reprex) is the smallest amount of code etc needed to reproduce a problem. The ability to make a one is a superpower for locating and solving problems.

There are two basic approaches:

  • restart from scratch, make a new document that contains only what is needed to reproduce the problem. This is useful when you know where the problem is.
  • divide and conquer, make a copy of your document (perhaps the whole project) and delete it bit by bit until the problem disappears, when add the last bit again.

With a reprex it is easier and faster to understand and perhaps fix the problem, and is needed to ask a question on stackoverflow.com or elsewhere.