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 68 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))
Pipe operator missing function call
Pattern: pipe operator requires a function call
The pipe operator (|> or %>%) expects a function call on the right side, but found something else like a bare name or expression.
x |> mean # missing parentheses
x |> mean()
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
Join type mismatch
Pattern: Can't join on .* incompatible types
You tried to join two data frames on a column, but the column has different types in each data frame (e.g., character vs numeric).
# df1$id is numeric, df2$id is character left_join(df1, df2, by = "id")
df2 <- df2 %>% mutate(id = as.numeric(id)) left_join(df1, df2, by = "id")
Names do not match (rbind)
Pattern: names do not match previous names
You tried to rbind() or bind_rows() data frames that have different column names. All data frames must have matching column names.
rbind(data.frame(x = 1), data.frame(y = 2))
library(dplyr) bind_rows(data.frame(x = 1), data.frame(x = 2))
Argument of length zero
Pattern: argument of length 0
A function received an empty (zero-length) argument. This often happens when a variable is NULL or when subsetting returns nothing.
x <- c()
if (x > 0) print("positive") # length 0x <- c()
if (length(x) > 0 && x > 0) print("positive")Data reading row mismatch
Pattern: line \d+ did not have \d+ elements
While reading a file (read.csv, read.table), a row had a different number of fields than expected. The file may have inconsistent delimiters or missing values.
read.csv("messy_data.csv")read.csv("messy_data.csv", fill = TRUE)
# or specify the correct separator:
read.csv("messy_data.csv", sep = ";")More columns than column names
Pattern: more columns than column names
The data file has more columns of data than header names. This often happens when the delimiter appears inside data values or the header row is shorter.
read.csv("data.csv") # data has unquoted commas in fieldslibrary(readr)
read_csv("data.csv") # handles quoting better
# or
read.csv("data.csv", quote = "\"")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
Cannot subset non-existent columns
Pattern: Can't subset columns that don't exist
You tried to select or access columns that don't exist in the data frame. This is the tidyverse equivalent of 'undefined columns selected'.
df %>% select(revnue, date) # typo in revenue
df %>% select(revenue, date)
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)
Encoding / iconv error
Pattern: cannot convert|invalid byte sequence
R encountered characters in an encoding it can't handle. The file may use a different encoding than expected (e.g., Latin-1 vs UTF-8).
read.csv("european_data.csv") # file is latin1 encodedread.csv("european_data.csv", fileEncoding = "latin1")
# or
readr::read_csv("european_data.csv",
locale = readr::locale(encoding = "latin1"))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))
dplyr column not found
Pattern: Can't find column|Column .* doesn't exist
dplyr can't find a column you referenced by name. This usually means a typo or the column was removed in a prior step.
df %>% select(reveneu) # typo
df %>% select(revenue) # correct name
Join column not found
Pattern: Join columns? .* must be present in the data
The column you specified in the by argument of a join doesn't exist in one or both of the data frames.
left_join(df1, df2, by = "user_id") # column missing in df2
left_join(df1, df2, by = c("user_id" = "id"))summarise result size
Pattern: Result must be size 1, not
Inside summarise(), each summary expression must return a single value per group. You used a function that returns multiple values.
df %>% group_by(category) %>% summarise(values = range(price))
df %>% group_by(category) %>% summarise(min_price = min(price), max_price = max(price))
Missing ggplot2 aesthetics
Pattern: geom_.* requires the following missing aesthetics
A ggplot2 geom layer requires certain aesthetic mappings (like x, y, fill, color) that you haven't provided.
ggplot(df) + geom_point() # missing x and y
ggplot(df, aes(x = weight, y = height)) + geom_point()
ggplot2 data must be a data frame
Pattern: data must be a data\.frame
ggplot2 requires a data frame (or tibble) as its data argument. You passed a matrix, vector, or other incompatible type.
mat <- matrix(1:9, nrow = 3) ggplot(mat, aes(x = V1, y = V2)) + geom_point()
df <- as.data.frame(matrix(1:9, nrow = 3)) ggplot(df, aes(x = V1, y = V2)) + geom_point()
Object is not a data frame
Pattern: object is not a data frame
A function expected a data frame but received a different object type (matrix, vector, list, etc.).
mat <- matrix(1:9, nrow = 3) subset(mat, V1 > 2)
df <- as.data.frame(matrix(1:9, nrow = 3)) subset(df, V1 > 2)
MODELING & REGRESSION ERRORS
NA/NaN/Inf in model fit
Pattern: na\/nan\/inf in ['"]?(x|y)|NA.*NaN.*Inf.*foreign function
Your data contains NA, NaN, or Inf values that the modeling function cannot handle. Most R model fitting functions don't tolerate missing or infinite values.
lm(y ~ x, data = df) # df contains NA values
lm(y ~ x, data = na.omit(df)) # or lm(y ~ x, data = df, na.action = na.exclude)
Singular or rank-deficient fit
Pattern: (nearly )?singular fit|rank-deficient
Your model has perfect multicollinearity — some predictors are exact linear combinations of others, making the model unsolvable. This often happens with dummy variable traps or redundant features.
# pct_male + pct_female always = 100 lm(y ~ pct_male + pct_female, data = df)
lm(y ~ pct_male, data = df) # drop one redundant predictor
GLM did not converge
Pattern: algorithm did not converge
The iterative algorithm used to fit the generalized linear model failed to find a stable solution within the maximum number of iterations. This often indicates perfect separation in logistic regression.
glm(y ~ x, family = binomial, data = df)
glm(y ~ x, family = binomial, data = df,
control = list(maxit = 100))Fitted probabilities 0 or 1
Pattern: fitted probabilities numerically 0 or 1
In logistic regression, some predicted probabilities are extremely close to 0 or 1, indicating perfect or near-perfect separation. A predictor perfectly separates the outcome.
# x perfectly predicts y glm(default ~ balance, family = binomial, data = df)
# Use penalized regression library(glmnet) fit <- cv.glmnet(x_matrix, y, family = "binomial")
Factor has new levels in predict
Pattern: factor .* has new levels
Your prediction data contains factor levels that weren't present in the training data. The model doesn't know how to handle unseen categories.
# Training had sectors: Tech, Finance # Test has sector: Healthcare predict(model, new_data)
# Ensure consistent factor levels new_data$sector <- factor(new_data$sector, levels = levels(train_data$sector))
Contrasts require 2+ factor levels
Pattern: contrasts can be applied only to factors with 2 or more levels
A factor variable in your model has only one level (or zero after removing NAs). R needs at least two levels to create contrast (dummy) variables.
# region has only one unique value after filtering lm(price ~ region + size, data = df)
# Remove constant factors df_clean <- df[df$region %in% names(which(table(df$region) > 0)), ] lm(price ~ size, data = df_clean)
Invalid model formula
Pattern: invalid model formula
The formula you passed to a modeling function has invalid syntax. Formulas use ~ to separate response from predictors, and + to add terms.
lm(y = x1 + x2, data = df) # wrong operator
lm(y ~ x1 + x2, data = df)
DATE & TIME ERRORS
All date formats failed to parse
Pattern: All formats failed to parse
The lubridate parsing function couldn't match your date string to any expected format. The date string format doesn't match the function you used (e.g., using mdy() on a day-month-year string).
library(lubridate)
ymd("03/15/2024") # this is mdy formatlibrary(lubridate)
mdy("03/15/2024") # correct function for month/day/yearCharacter not in standard date format
Pattern: character string is not in a standard unambiguous format
as.Date() or as.POSIXct() can't automatically parse your date string because it doesn't match the default format (YYYY-MM-DD). You need to specify the format explicitly.
as.Date("03/15/2024") # ambiguous formatas.Date("03/15/2024", format = "%m/%d/%Y")
# or
lubridate::mdy("03/15/2024")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 efficientCOMMON WARNINGS
NaNs produced
Pattern: NaNs produced
A mathematical operation produced Not-a-Number results. This happens with operations like sqrt() on negative numbers or log() of zero/negative values.
sqrt(-1) log(-5)
sqrt(pmax(x, 0)) # clamp negatives to 0 log(pmax(x, 1e-10)) # avoid log of zero
Deprecated function
Pattern: is deprecated
You're using a function or argument that has been replaced by a newer alternative. It still works but may be removed in future versions.
df %>% summarise_each(funs(mean)) # deprecated
df %>% summarise(across(everything(), mean))
Grouped output warning
Pattern: has grouped output.*\.groups
After summarise(), dplyr warns about the grouping structure of the result. This is informational — it tells you whether groups were dropped or kept.
df %>% group_by(a, b) %>% summarise(n = n())
df %>% group_by(a, b) %>% summarise(n = n(), .groups = "drop")
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.
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")Stack overflow / recursion depth exceeded
Pattern: stack overflow|evaluation depth
Your code has infinite recursion — a function keeps calling itself without a proper stopping condition. R has a limited call stack and this error occurs when it's exceeded.
f <- function(x) f(x + 1) # no base case f(1)
f <- function(x) {
if (x > 100) return(x) # base case
f(x + 1)
}
f(1)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 68 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.