Get Started →
FREE R TOOL

R Error?

Explained instantly.

Paste your R error message below and get a plain-English explanation with a step-by-step fix. No signup required.

01 — COMPLETE R ERROR REFERENCE

All 41 R Errors Explained

A complete reference of common R error messages, what they mean, and how to fix them. Bookmark this page for quick lookups.

OBJECT ERRORS

Object not found

Pattern: object '([^']+)' not found

R cannot find a variable or object with the name you used. This usually means you haven't created it yet, misspelled it, or it exists in a different environment.

BAD
# Forgot to create the variable
mean(my_data)
GOOD
my_data <- c(1, 2, 3, 4, 5)
mean(my_data)

SYNTAX ERRORS

Unexpected token

Pattern: unexpected '([^']+)' in

R encountered a character or symbol it didn't expect at that position. This usually means a missing comma, parenthesis, bracket, or operator.

BAD
data.frame(x = 1:5 y = 6:10)
GOOD
data.frame(x = 1:5, y = 6:10)

Unexpected end of input

Pattern: unexpected end of input

R reached the end of your code but was still expecting more — usually a closing parenthesis, bracket, or brace.

BAD
if (x > 0) {
  print("positive")
# missing closing brace
GOOD
if (x > 0) {
  print("positive")
}

Unexpected symbol

Pattern: unexpected symbol in

R found two symbols next to each other without an operator or separator between them. Common cause: missing comma, pipe, or operator.

BAD
my data <- c(1, 2, 3)
GOOD
my_data <- c(1, 2, 3)

Unexpected string constant

Pattern: unexpected string constant

R found a string where it wasn't expected, usually because of a missing comma or operator before it.

BAD
c("apple" "banana" "cherry")
GOOD
c("apple", "banana", "cherry")

Extra closing parenthesis

Pattern: unexpected .+\).+ in

There's an extra closing parenthesis that doesn't match any opening parenthesis.

BAD
mean(c(1, 2, 3)))
GOOD
mean(c(1, 2, 3))

PACKAGE ERRORS

Package not installed

Pattern: there is no package called '([^']+)'

The package you're trying to load hasn't been installed on your system yet.

BAD
library(tidyvers)  # typo!
GOOD
install.packages("tidyverse")
library(tidyverse)

Package version mismatch

Pattern: package '([^']+)' was built under R version

The installed package was compiled with a newer version of R than you're running. It may still work, but some features could be unreliable.

BAD
# Running R 4.2 with a package built for R 4.3
GOOD
# Update R, or reinstall:
install.packages("dplyr")

Package load failed

Pattern: package or namespace load failed

The package exists but couldn't be loaded, usually because one of its dependencies is missing or incompatible.

BAD
library(rJava)  # requires Java runtime
GOOD
# Install system dependency first, then:
install.packages("rJava", dependencies = TRUE)

TYPE & COERCION ERRORS

Non-numeric argument to operator

Pattern: non-numeric argument to binary operator

You tried to do math (like +, -, *, /) on something that isn't a number, such as a character string or factor.

BAD
"10" + 5  # "10" is a string, not a number
GOOD
as.numeric("10") + 5

Argument not numeric or logical

Pattern: argument is not numeric or logical

A function that expects numbers (like mean, sum, sd) received non-numeric data such as character strings.

BAD
mean(c("1", "2", "3"))  # character vector
GOOD
mean(as.numeric(c("1", "2", "3")))

Cannot coerce type

Pattern: cannot coerce type '([^']+)' to vector of type '([^']+)'

R tried to convert one data type to another but failed because the conversion isn't possible or doesn't make sense.

BAD
as.numeric(list(1, "a", TRUE))
GOOD
as.numeric(c(1, 0, 1))

Invalid argument type

Pattern: invalid '([^']+)' argument

An argument you passed to a function is the wrong type. The function expected one type but received another.

BAD
substr("hello", "2", "4")  # indices should be numeric
GOOD
substr("hello", 2, 4)

Replacement length mismatch

Pattern: replacement has (\d+) rows?, data has (\d+)

You tried to assign a value to a column or vector, but the length of the new value doesn't match the existing data.

BAD
df$new_col <- c(1, 2, 3)  # but df has 5 rows
GOOD
df$new_col <- c(1, 2, 3, 4, 5)  # match row count

Differing number of rows

Pattern: arguments imply differing number of rows

When creating a data frame, the vectors you provided have different lengths and R can't recycle them evenly.

BAD
data.frame(x = 1:3, y = 1:5)
GOOD
data.frame(x = 1:5, y = 1:5)

Vector length not a multiple

Pattern: longer object length is not a multiple of shorter object length

You're operating on two vectors where the longer one's length is not a clean multiple of the shorter one. R will still recycle, but the result may not be what you intended.

BAD
c(1, 2, 3) + c(10, 20)  # 3 is not a multiple of 2
GOOD
c(1, 2, 3) + c(10, 20, 30)  # same length

Non-conformable arguments

Pattern: non-conformable arguments

Matrix multiplication or a similar operation failed because the dimensions don't match. The number of columns in the first matrix must equal the number of rows in the second.

BAD
A <- matrix(1:6, nrow = 2)
B <- matrix(1:4, nrow = 2)
A %*% B  # 2x3 times 2x2 fails
GOOD
A <- matrix(1:6, nrow = 2)
B <- matrix(1:6, nrow = 3)
A %*% B  # 2x3 times 3x2 works

NAs from coercion

Pattern: NAs introduced by coercion

R tried to convert values to another type (usually numeric) but some values couldn't be converted, so they became NA.

BAD
as.numeric(c("1", "2", "three"))
GOOD
# Clean first:
x <- c("1", "2", "three")
x[x == "three"] <- "3"
as.numeric(x)

Replacement length not a multiple

Pattern: number of items to replace is not a multiple

The number of values you're assigning doesn't evenly divide into the number of positions being replaced.

BAD
x <- 1:10
x[1:6] <- c(0, 0)  # 2 doesn't divide into 6
GOOD
x <- 1:10
x[1:6] <- rep(0, 6)  # correct length

Unimplemented type

Pattern: unimplemented type '([^']+)' in

You passed an object type that the function doesn't support. Often happens when passing a list where a vector is expected.

BAD
sort(list(3, 1, 2))
GOOD
sort(c(3, 1, 2))  # use a vector, not a list

SUBSCRIPT & INDEXING ERRORS

Subscript out of bounds

Pattern: subscript out of bounds

You tried to access an element at a position that doesn't exist — like asking for the 10th element of a 5-element vector.

BAD
x <- c(1, 2, 3)
x[5]  # only 3 elements
GOOD
x <- c(1, 2, 3)
x[3]  # valid index

Undefined columns selected

Pattern: undefined columns selected

You tried to select a column that doesn't exist in your data frame, usually due to a typo or wrong column name.

BAD
df[, "Sepal.length"]  # wrong case
GOOD
df[, "Sepal.Length"]  # correct case

$ operator on atomic vector

Pattern: \$ operator is invalid for atomic vectors

You used $ to access a named element, but the object is a simple vector, not a list or data frame.

BAD
x <- c(a = 1, b = 2)
x$a
GOOD
x <- c(a = 1, b = 2)
x["a"]

Incorrect number of dimensions

Pattern: incorrect number of dimensions

You used multi-dimensional indexing (like [row, col]) on an object that doesn't have that many dimensions.

BAD
x <- 1:10
x[1, 2]  # x is a vector, not a matrix
GOOD
x <- 1:10
x[1]  # single index for vectors

Recursive indexing failed

Pattern: recursive indexing failed

You tried to access a nested element in a list using [[ ]] but the path doesn't exist — one of the intermediate levels is NULL or missing.

BAD
result[["model"]][["coefficients"]]  # "model" may not exist
GOOD
# Check structure first:
str(result)
# Then access safely:
if (!is.null(result$model)) result$model$coefficients

FILE & CONNECTION ERRORS

Cannot open connection

Pattern: cannot open the connection

R couldn't open a file or URL. The file might not exist, the path might be wrong, or you don't have permission to access it.

BAD
read.csv("data.csv")  # file not in working directory
GOOD
read.csv("/path/to/data.csv")  # absolute path
# or
setwd("/path/to/")
read.csv("data.csv")

File not found

Pattern: no such file or directory

The file path you specified doesn't point to an existing file. The path might be wrong, or the file hasn't been created yet.

BAD
source("analysis.R")  # file doesn't exist here
GOOD
# Check first:
file.exists("analysis.R")
list.files()  # see what files are available

Permission denied

Pattern: cannot open file '([^']+)': Permission denied

The file exists but R doesn't have permission to read or write to it. This is an operating system restriction.

BAD
write.csv(df, "/system/protected/file.csv")
GOOD
write.csv(df, "~/Documents/file.csv")

Connection failed

Pattern: cannot open connection

R failed to establish a connection to a file, URL, or database. The resource may not exist or be unreachable.

BAD
read.csv("http://broken-url.com/data.csv")
GOOD
# Verify URL is accessible first
url <- "https://valid-url.com/data.csv"
read.csv(url)

FUNCTION ERRORS

Function not found

Pattern: could not find function "([^"]+)"

R doesn't recognize the function you're trying to call. The package containing it may not be loaded, or the function name is misspelled.

BAD
# ggplot2 not loaded
ggplot(data, aes(x, y)) + geom_point()
GOOD
library(ggplot2)
ggplot(data, aes(x, y)) + geom_point()

Unused argument

Pattern: unused argument

You passed an argument to a function that doesn't accept it. This often happens from typos in argument names or using arguments from a different function.

BAD
mean(x = c(1, 2, 3), na.action = TRUE)
GOOD
mean(x = c(1, 2, 3), na.rm = TRUE)

Missing required argument

Pattern: argument "([^"]+)" is missing, with no default

A function requires a specific argument that you didn't provide, and there's no default value for it.

BAD
rnorm()  # n is required
GOOD
rnorm(n = 10)  # specify how many random numbers

Argument matched multiple times

Pattern: formal argument "([^"]+)" matched by multiple actual arguments

You provided the same argument twice — once by name and once by position, or used the same name twice.

BAD
rnorm(10, mean = 0, 0)  # mean specified twice
GOOD
rnorm(10, mean = 0, sd = 1)

Duplicate arguments

Pattern: duplicate '([^']+)' arguments

You passed the same named argument more than once to a function.

BAD
plot(x, y, col = "red", col = "blue")
GOOD
plot(x, y, col = "red")

Attempt to apply non-function

Pattern: attempt to apply non-function

You tried to call something as a function (using parentheses) but it isn't a function. A common cause is accidentally overwriting a built-in function name with a variable.

BAD
c <- 5
c(1, 2, 3)  # c is now a number, not the combine function
GOOD
rm(c)  # remove the variable
c(1, 2, 3)  # now works

Closure is not subsettable

Pattern: object of type 'closure' is not subsettable

You tried to use [ ] or $ on a function. This usually means you forgot the parentheses to call the function, or a variable has the same name as a function.

BAD
data[1, ]  # if data is still the function, not your data frame
GOOD
my_data <- read.csv("file.csv")
my_data[1, ]

No applicable method

Pattern: no applicable method for '([^']+)'

You called a generic function on an object type it doesn't know how to handle. The function exists but has no implementation for your object's class.

BAD
summary(Sys.time)  # passing the function, not calling it
GOOD
summary(Sys.time())  # call the function first

Missing x and y for plot

Pattern: supply both 'x' and 'y' or a matrix-like

The plotting function needs either both x and y vectors, or a single matrix/data frame. You provided something it can't interpret.

BAD
plot()  # no data provided
GOOD
plot(x = 1:10, y = rnorm(10))

MEMORY ERRORS

Cannot allocate memory

Pattern: cannot allocate vector of size

R ran out of memory trying to create a large object. Your data or computation requires more RAM than available.

BAD
huge_matrix <- matrix(0, nrow = 1e8, ncol = 100)
GOOD
# Process in chunks:
library(data.table)
dt <- fread("large_file.csv")  # more memory efficient

OTHER ERRORS

Missing value in condition

Pattern: missing value where TRUE\/FALSE needed

An if statement or while loop received NA instead of TRUE or FALSE. This happens when the condition evaluates to a missing value.

BAD
x <- NA
if (x > 0) print("positive")
GOOD
x <- NA
if (!is.na(x) && x > 0) print("positive")

Condition has length > 1

Pattern: the condition has length > 1

An if() statement received a vector with multiple values instead of a single TRUE or FALSE. if() only works with single logical values.

BAD
x <- c(1, 2, 3)
if (x > 2) print("big")
GOOD
x <- c(1, 2, 3)
if (any(x > 2)) print("at least one big")
02 — FAQ

Common questions about R errors

What does "object not found" mean in R? +

The "object not found" error means you're referencing a variable or function that doesn't exist in your current R environment. This is usually caused by a typo in the variable name, forgetting to run the line that creates it, or the variable being defined in a different scope or script.

How do I fix "could not find function" in R? +

Load the package that contains the function using library(package_name). If the package isn't installed yet, run install.packages("package_name") first. Also double-check for typos in the function name.

Why does R give "non-numeric argument to binary operator"? +

You tried to do math on something that isn't a number — like adding a string to an integer. Use class() to check your data types and as.numeric() to convert string numbers to actual numbers.

Can this tool explain any R error? +

This tool covers the 41 most common R errors. For errors not in our database, RChat's AI assistant can analyze any R error in real-time, explain it in context of your actual code, and suggest specific fixes automatically.

03 — GO FURTHER

Want AI that fixes R errors automatically?

RChat's AI detects errors in your R code, explains them in context, and applies fixes with one click.

Free tokens on signup · No credit card required