3.4 Problems, Bugs and Errors

It is not uncommon to get errors when typing a command in R. Errors often occur when you misspell the code or use the wrong code for the job at hand. In these cases, R will print a message (in red) telling you why it cannot do what you want it to do. Sometimes this message is quite clear, like telling you to install an extra package. Other times it is more complicated and requires some extra work. In these cases, there are four questions you should ask yourself:

  1. Have I downloaded all the packages I need?
  2. Are all my packages up to date?
  3. Did I spell the commands correctly?
  4. Is the data in the correct form or format?

If none of these provide a solution, you can always look online to see if others have encountered the same problem. Often, copying and pasting your error into a search engine will give you other examples, and usually a solution. A well-known place for solutions is Stack Overflow, where you can share your problem with others and see if someone can offer a solution. However, make sure you read through the problems that have already been posted to make sure you do not post the same problem twice. We have also compiled a list of problems encountered by people who have used this book, along with their solutions, in this spreadsheet.