Common R Error Messages

Because we all love the meticulously documented yet mildly inscrutable error messages that R occasionally throws, here are some notes on what they are talking about and how to deal with them.

Root Cause: improper method of looking at a single cell of that data type

Root Cause: R cannot find the file you’re trying to open. Generally an issue with how you are pointing to your working directory. Could also be a problem with an old / bad file reference hiding out in your environment from a past project or imported script. Reset with setwd().

Type conversion error between a list object and the as.numeric function which expects either a single element or a single vector of values. We explain how to solve this issue and why R threw the error in the first place.

Common variant on the first error on this list. You’re feeding a list to something that expects an atomic vector.

Usually a syntax error caused by omitting a critical operator (+, -, /, *) from a calculation and using brackets immediately afterwards. R parses that as function instead of bad syntax and takes it seriously enough that you wonder why it’s trying to execution functions that don’t exist.

This is a syntax error related to matching how you access a data element. Lists use $, atomic vendors use brackets to identify specific elements

Another “I can’t find it” error. Generally either related to typographical errors in declaring or calling a function or a missing library declaration. Occasionally caused by loading packages that contain the same function name into the same namespace. Sometimes can be even weirder…

A warning, not an error, but worth heeding since it often indicates you are applying a function to situations that it wasn’t designed to address. Indicates you are passing a vector (or similar) to into a function which was designed to handle a single value.

Indicates you have passed a missing value to a function which is expecting a Boolean value.

This error can occur for multiple reasons but generally is related to syntax error in your selection criteria

  • Object of type ‘closure’ is not subsettable: Nuisance error which occurs when you attempt to treat a variable that contains a closure as if it were an index-able function. Two common sources: the reactive () function in R shiny development and naming variables similar names as the base R functions.