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.
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.
# Forgot to create the variable mean(my_data)
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.
data.frame(x = 1:5 y = 6:10)
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.
if (x > 0) {
print("positive")
# missing closing braceif (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.
my data <- c(1, 2, 3)
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.
c("apple" "banana" "cherry")c("apple", "banana", "cherry")Extra closing parenthesis
Pattern: unexpected .+\).+ in
There's an extra closing parenthesis that doesn't match any opening parenthesis.
mean(c(1, 2, 3)))
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.
library(tidyvers) # typo!
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.
# Running R 4.2 with a package built for R 4.3
# 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.
library(rJava) # requires Java runtime
# 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.
"10" + 5 # "10" is a string, not a number
as.numeric("10") + 5Argument 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.
mean(c("1", "2", "3")) # character vectormean(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.
as.numeric(list(1, "a", TRUE))
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.
substr("hello", "2", "4") # indices should be numericsubstr("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.
df$new_col <- c(1, 2, 3) # but df has 5 rows
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.
data.frame(x = 1:3, y = 1:5)
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.
c(1, 2, 3) + c(10, 20) # 3 is not a multiple of 2
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.
A <- matrix(1:6, nrow = 2) B <- matrix(1:4, nrow = 2) A %*% B # 2x3 times 2x2 fails
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.
as.numeric(c("1", "2", "three"))# 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.
x <- 1:10 x[1:6] <- c(0, 0) # 2 doesn't divide into 6
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.
sort(list(3, 1, 2))
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.
x <- c(1, 2, 3) x[5] # only 3 elements
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.
df[, "Sepal.length"] # wrong case
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.
x <- c(a = 1, b = 2) x$a
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.
x <- 1:10 x[1, 2] # x is a vector, not a matrix
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.
result[["model"]][["coefficients"]] # "model" may not exist
# 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.
read.csv("data.csv") # file not in working directoryread.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.
source("analysis.R") # file doesn't exist here# Check first:
file.exists("analysis.R")
list.files() # see what files are availablePermission 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.
write.csv(df, "/system/protected/file.csv")
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.
read.csv("http://broken-url.com/data.csv")# 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.
# ggplot2 not loaded ggplot(data, aes(x, y)) + geom_point()
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.
mean(x = c(1, 2, 3), na.action = TRUE)
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.
rnorm() # n is required
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.
rnorm(10, mean = 0, 0) # mean specified twice
rnorm(10, mean = 0, sd = 1)
Duplicate arguments
Pattern: duplicate '([^']+)' arguments
You passed the same named argument more than once to a function.
plot(x, y, col = "red", col = "blue")
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.
c <- 5 c(1, 2, 3) # c is now a number, not the combine function
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.
data[1, ] # if data is still the function, not your data frame
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.
summary(Sys.time) # passing the function, not calling it
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.
plot() # no data provided
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.
huge_matrix <- matrix(0, nrow = 1e8, ncol = 100)
# Process in chunks:
library(data.table)
dt <- fread("large_file.csv") # more memory efficientOTHER 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.
x <- NA
if (x > 0) print("positive")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.
x <- c(1, 2, 3)
if (x > 2) print("big")x <- c(1, 2, 3)
if (any(x > 2)) print("at least one big")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.
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.