Troubleshooting

What to check when R does not produce the expected result

Plain-language help for common problems with the starter project, scripts, objects, and R commands.

Errors are information about where R became unable to continue. Begin with the first error message, check the code immediately above it, and change only one thing at a time.

A Quick Recovery Routine

  1. Stop and read the first message in the Console.
  2. Check whether the > prompt has returned.
  3. Compare the code with the workbook example.
  4. Check spelling, capitalization, parentheses, commas, and quotation marks.
  5. Run the setup line again if an expected object is missing.
  6. Run the smallest complete section that could produce the result.

Common Problems

What you see What it usually means What to try
object 'eammi' not found The shared setup has not created the data object in this R session. Open the project and run source("scripts/_setup.R").
R cannot find scripts/_setup.R or the data file The RStudio project may not be open, or part of the starter folder was moved. Open exploring-statistics-r.Rproj and keep the starter files together.
A + prompt R is waiting for the rest of an unfinished command. Press Esc, check for a missing parenthesis or quotation mark, and run the complete command.
could not find function The setup section may not have run, or the function name may be misspelled. Run the setup line and compare the function spelling with the example.
object 'VariableName' not found The variable name may be misspelled or used outside the data frame. Check names(eammi) and remember that capitalization matters.
A graph does not appear The plotting code may be incomplete or the wrong Output tab may be selected. Run the entire graph expression and open the Plots tab.
The output differs from the workbook An earlier recode, filter, or object may differ. Restart R, run setup, and repeat the chapter code in order.

Read An Error Message

You do not need to understand every word. Look first for:

  • the object or function named in the message;
  • a line number, if one is shown;
  • wording such as not found, unexpected, or missing; and
  • the first error, rather than messages that followed it.

Copying only the final line of a long message can remove useful context. When asking for help, include the code you ran and the first complete error message.

Restart When The Sequence Is Unclear

If you have run sections out of order and no longer know which objects have been changed:

  1. choose Session > Restart R;
  2. confirm that the project is still open;
  3. run source("scripts/_setup.R"); and
  4. repeat the chapter code from the beginning.

Restarting R clears objects from memory. It does not delete your script or data files.

Before Asking For Help

Be ready to describe:

  • which script you opened;
  • which line or section you ran;
  • what you expected;
  • what appeared instead; and
  • the complete first error message.

This information helps another person reproduce the problem and identify the relevant step.