Handling Errors & Warnings in R | List of Typical Messages & How to Solve
This page explains some of the most common error and warning messages in the R programming language.
Below, you can find a list of typical errors and warnings. When clicking on the bullet points of the list, you are headed to detailed instructions on how to deal with the corresponding error or warning message.
You may use the list as cheat sheet whenever you are facing an error or warning message in R.
Let’s dive into the examples!

List of Typical Errors & Warnings in R (+ Examples)
- [ reached getOption(“max.print”) — omitted X entries ]
- `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
- `summarise()` has grouped output by ‘X’. You can override using the `.groups` argument.
- Don’t know how to automatically pick scale for object of type standardGeneric. Defaulting to continuous.
- Error: ‘\U’ used without hex digits in character string starting “”C:\U”
- Error: `data` must be a data frame, or other object coercible by `fortify()`, not an S3 object with class uneval
- Error: (list) object cannot be coerced to type ‘double’
- Error: ‘R’ is an unrecognized escape in character string starting “”C:R”
- Error: Aesthetics must be either length 1 or the same as the data
- Error: attempt to apply non-function
- Error: Can’t rename columns that don’t exist.
- Error: cannot allocate vector of size X Gb
- Error: Continuous value supplied to discrete scale
- Error: Discrete value supplied to continuous scale
- Error: geom_point requires the following missing aesthetics: x, y
- Error: Insufficient values in manual scale. X needed but only Y provided.
- Error: Invalid input: date_trans works with objects of class Date only
- Error: JAVA_HOME cannot be determined from the Registry
- Error: Mapping should be created with `aes()` or `aes_()`.
- Error: object X not found
- Error: stat_count() must not be used with a y aesthetic.
- Error: StatBin requires a continuous x variable: the x variable is discrete.Perhaps you want stat=”count”?
- Error: unexpected ‘,’ in “,”
- Error: unexpected ‘}’ in X
- Error: unexpected ‘=’ in “=”
- Error: unexpected ‘)’ in “)”
- Error: unexpected ‘else’ in “else”
- Error: unexpected input in X
- Error: unexpected numeric constant in X
- Error: unexpected SPECIAL in X
- Error: unexpected string constant in X
- Error: unexpected symbol in X
- Error: X must only be used inside dplyr verbs.
- Error in .Call.graphics : invalid graphics state
- Error in .subset(x, j) : invalid subscript type ‘list’
- Error in `levels<-`(`*tmp*`, value = as.character(levels)) : factor level is duplicated
- Error in aggregate.data.frame(as.data.frame(x), …) : arguments must have same length
- Error in apply(data) : dim(X) must have a positive length
- Error in as.Date.numeric(X) : ‘origin’ must be supplied
- Error in as.POSIXlt.character(x, tz, …) : character string is not in a standard unambiguous format
- Error in barplot.default(X) : ‘height’ must be a vector or a matrix
- Error in charToDate(x) : character string is not in a standard unambiguous format
- Error in colMeans(x, na.rm = TRUE) : ‘x’ must be numeric
- Error in contrasts : contrasts can be applied only to factors with 2 or more levels
- Error in cut.default : ‘breaks’ are not unique
- Error in do_one(nmeth) : NA/NaN/Inf in foreign function call (arg 1)
- Error in eval(predvars, data, env) : numeric ‘envir’ arg not of length one
- Error in file(file, “rt”) : cannot open the connection
- Error in file(file, “rt”) : invalid ‘description’ argument
- Error in fix.by(by.y, y) : ‘by’ must specify a uniquely valid column
- Error in FUN(X[[i]], …) : object ‘X’ not found
- Error in FUN : invalid ‘type’ (character) of argument
- Error in FUN : invalid ‘type’ (list) of argument
- Error in hist.default(X) : ‘x’ must be numeric
- Error in if (NA) { : missing value where TRUE/FALSE needed
- Error in library(“X”) : there is no package called ‘X’
- Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, …) : 0 (non-NA) cases
- Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, …) : NA/NaN/Inf in ‘x’
- Error in load(“X.rds”) : bad restore file magic number (file may be corrupted) — no data loaded
- Error in max.item – min.item : non-numeric argument to binary operator
- Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) : ‘data’ must be a data.frame, environment, or list
- Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) : factor X has new levels Y
- Error in names(X) : ‘names’ attribute must be the same length as the vector
- Error in Ops.data.frame() : only defined for equally-sized data frames
- Error in parse(text) : <text>:1:2: unexpected symbol
- Error in plot.new() : figure margins too large
- Error in plot.window(…) : need finite ‘xlim’ values
- Error in plot.xy(xy.coords(x, y), type = type, …) : plot.new has not been called yet
- Error in rbind(deparse.level, …) : numbers of columns of arguments do not match
- Error in read.table : more columns than column names
- Error in read.table(file = file, header = header, sep = sep, quote = quote, : duplicate ‘row.names’ are not allowed
- Error in rep(X) : invalid ‘times’ argument
- Error in rowSums & colSums – ‘x’ must be an array of at least two dimensions
- Error in scan : line 1 did not have X elements
- Error in setwd(X) : cannot change working directory
- Error in solve.default(X) : Lapack routine dgesv: system is exactly singular
- Error in sort.int(x, na.last = na.last, decreasing = decreasing, …) : ‘x’ must be atomic
- Error in stripchart.default(x1, …) : invalid plotting method
- Error in strsplit(X) : non-character argument
- Error in unique.default(x, nmax = nmax) : unique() applies only to vectors
- Error in UseMethod(“predict”) : no applicable method for ‘predict’ applied to an object of class “c(‘double’, ‘numeric’)”
- Error in X : $ operator is invalid for atomic vectors
- Error in X : argument is of length zero
- Error in X : arguments imply differing number of rows
- Error in X : attempt to select less than one element in get1index real
- Error in X : could not find function X
- Error in X : missing values are not allowed in subscripted assignments of data frames
- Error in X : incorrect number of dimensions
- Error in X : incorrect number of subscripts on matrix
- Error in X : invalid (do_set) left-hand side to assignment
- Error in X : invalid (NULL) left side of assignment
- Error in X : non-numeric argument to binary operator
- Error in X : object not interpretable as a factor
- Error in X : object of type ‘closure’ is not subsettable
- Error in X : replacement has Y rows, data has Z
- Error in X : requires numeric/complex matrix/vector arguments
- Error in X : subscript out of bounds
- Error in X : target of assignment expands to non-language object
- Error in X : undefined columns selected
- Error in X : unused argument
- Error in X %*% Y : non-conformable arguments
- Error in xy.coords(x, y, xlabel, ylabel, log) : ‘x’ and ‘y’ lengths differ
- geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?
- Please select a CRAN mirror for use in this session
- Scale for ‘fill’ is already present. Adding another scale for ‘fill’, which will replace the existing scale.
- The following objects are masked from ‘package:X’
- The following objects are masked from X
- Use of `data$X` is discouraged. Use `X` instead
- Warning: cannot remove prior installation of package ‘X’
- Warning message: ‘newdata’ had X rows but variables found have Y rows
- Warning message: In cor(X) : the standard deviation is zero
- Warning message: In is.na(data) : is.na() applied to non-(list or vector) of type ‘closure’
- Warning message: In mean.default(X) : argument is not numeric or logical: returning NA
- Warning message: In min/max(X) : no non-missing arguments to min/max; returning Inf
- Warning message: In scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : embedded nul(s) found in input
- Warning message: invalid factor level, NA generated
- Warning message: longer object length is not a multiple of shorter object length
- Warning message: NAs introduced by coercion
- Warning message: Removed X rows containing missing values
- Warning message: the condition has length > 1 and only the first element will be used
- Warning message in as.POSIXct.POSIXlt(x) : unknown timezone
- Warning message in Ops.factor : not meaningful for factors
- Warning message in read.table: incomplete final line found by readTableHeader
- Warning messages: In plot.window(…) : nonfinite axis limits [GScale(-inf,1,1, .); log=1]
- Warning messages: Removed 17 rows containing non-finite values (stat_bin).
Debugging in R – Some General Advice
Debugging in R can be a painful process. However, there are some useful tools and functions available that can be used to make the debugging more efficient.
One of these tools is the interactive debug mode, which is built into the RStudio IDE. This tool helps to find bugs by locating where the code is not working in the way you would expect, and can therefore be very helpful in case you are dealing with a more complex R code. You can read more about RStudio’s debug mode here.
Another useful method to handle errors and warnings is provided by the tryCatch function. This function can be used to check if an R code leads to an error or warning message, and it can be used to skip an error message in order to continue running the code. You can learn more about the application of the tryCatch function here.
In case you want to learn more about typical R programming error messages and the handling of these errors, you may also have a look at the following YouTube video. In the video, the speaker Andres Karjus explains some common error messages that beginners often get and how to quickly figure them out.
Please accept YouTube cookies to play this video. By accepting you will be accessing content from YouTube, a service provided by an external third party.
If you accept this notice, your choice will be saved and the page will refresh.
Note that there are usually different reasons why an error or warning message can occur. Please let me know in the comments in case the provided tips and tutorials on this page didn’t solve your problem.
Furthermore, please let me know in the comments in case the error or warning message you have problems with is not included in the previous list.
I’m looking forward to hearing from you in the comments!
26 Comments. Leave new
Error: grouping factors must have > 1 sampled level
Hey George,
Please have a look at this thread on Cross Validated. It seems to explain the error message.
Regards,
Joachim
Error in make.names(col.names, unique = TRUE) :
invalid multibyte string at ‘
Hey Vlad,
Could you please share your code?
Regards,
Joachim
Hello Joachim,
May i know what does it mean getting this warning “There were 50 or more warnings (use warnings() to see the first 50)”?
I am running a glmm analysis with the code something like this:
model <-glmer (richness ~ var1 + var2 + var3+(1|habitat), family = "poisson", data=xxx)
summary(model)
thanks in advance
Hey Esther,
This means that there have been many warnings after executing your code (i.e. more than 50). You may execute the following code to see them one-by-one:
Regards,
Joachim
Thanks Joachim,
Now if I run my glmm models I couldn’t get the results and got another warning messages which saying like this:
Warning messages:
1: In vcov.merMod(object, use.hessian = use.hessian) : variance-covariance matrix computed from finite-difference Hessian is not positive definite or contains NA values: falling back to var-cov estimated from RX
2: In vcov.merMod(object, correlation = correlation, sigm = sig) : variance-covariance matrix computed from finite-difference Hessian is not positive definite or contains NA values: falling back to var-cov estimated from RX >
When I got that warning messages, I’ve tried running my model using glmer.nb function instead glmer.
May I know what the difference of these two functions? Can I actually do that, I mean change the function to glmer.nb to see the influence of the variables for my study?
Thanks!
Unfortunately, I’m not an expert on this topic and I have never experienced this problem myself. However, I found this thread on Stack Overflow, which seems to discuss this warning message. Maybe this helps?
Regards,
Joachim
Dear Joachim
I receive an error while I’m converting .CEL file to TXT and normalizing them :
after using this command :
{
raw.data <-ReadAffy(verbose = FALSE,filenames= f[i],cdfname="hgu133acdf")
data.rma.norm = rma(raw.data)
}
it shows :
Error in exprs(object)[index, , drop = FALSE] : subscript out of bounds
,I don't know what is the cause of this error: it's bcz my data is too long or maybe a bug is in my data or some thing else,
It will be your kindness if guide me how I can fix this error ?
Hi Atie,
I do not have any experience with CEL files, but this error message is explained here.
I hope this helps!
Joachim
Hi Joachim,
Have you ever seen anything like this?
I was plotting a simple gray bar graph and wanted to add some color. I originally ran this:
ggplot(data=heartdata) + geom_bar(aes(x = fbs, fill = chol))
and it worked fine. I then played around trying to add some color and got this to work:
ggplot(data=chol_sev) + geom_bar(aes(x = fbs, fill =..chol..))
I then closed R studio but when I reopened the script the color plot would no longer work. I now receive the below error. any ideas?
Error in `f()`:
! Aesthetics must be valid computed stats. Problematic aesthetic(s): fill = ..chol…
Did you map your stat in the wrong layer?
Run `rlang::last_error()` to see where the error occurred.
Thank you!
Hey Jason,
Please excuse the delayed response. I was on a long holiday, so unfortunately I wasn’t able to reply sooner. Still need help with your code?
Regards,
Joachim
(Error in { : task 1 failed – “‘list’ object cannot be coerced to type ‘integer'”)
I get this error
Hey Jom,
Please excuse the delayed response. I was on a long holiday, so unfortunately I wasn’t able to reply sooner. Still need help with your code?
Regards,
Joachim
Hi Joachim
I found this error message during my R code using spatials data, and I don’t know how to resolve that. I don’t know if you help me with some idea:
” There were 12 warnings (use warnings() to see them) ”
Hey Nadine,
I’m sorry for the delayed response. I was on a long vacation, so unfortunately I wasn’t able to get back to you earlier. Do you still need help with your syntax?
Regards,
Joachim
Yes please !
I also have another question and I don’t know if you have time to direct me to it. I am looking to do a classification using deep learning for the identification of individual trees in a forest plot. I work on images taken with a multispectral sensor. I do it on the point cloud because the results obtained using the raster did not convince me. Normally you have to go through segmentation, alignment and classification. I did the segmentation with Dalpont algorithm and silva algorithm. But I can’t find the function I need for the two other steps (alignment and classification). I wonder if you have any idea about this.
Hi Nadine,
Regarding your warning message, you could execute the following code in the RStudio console to see the actual warnings:
Regarding your additional question, unfortunately I’m not an expert on this topic. However, I run a Facebook discussion group where people can ask questions about R programming and statistics. Could you post your question there? This way, others can contribute/read as well: https://www.facebook.com/groups/statisticsglobe
Regards,
Joachim
Hi
I am executing function in R studio
and I got this error (Error in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L, :
invalid value 0 for ‘digits’ argument)
I don’t know how to fix
please help me if possible
Hello Ola,
I am not very familiar with that error. But my quick search shows that it pops up when there is a problem with the convergence of the glm algorithm. I found this StackOverflow thread. I hope it helps you.
Regards,
Cansu
Hi,
I have an excel with many columns, how can I convert all of them into numeric variables in Rstudio?
error: the non-numeric argument to mathematical function
I get this error
Hello Adrian,
Yes, you get this error because your variables are not numeric. I think our tutorial: Convert Data Frame Column to Numeric in R would help you with this.
Regards,
Cansu
Error in `[<-.data.frame`(`*tmp*`, is.na(df$Ozone), "Ozone", value = c(41L, :
replacement has 153 rows, data has 37
Hi Tejas,
Please have a look at this tutorial, it explains your error message.
Regards,
Joachim
Hi,
When trying to run an ordered random forest, I got this error message:
Error in check_Y(Y, X) :
The number of outcomes does not equal the number of features. Check your data.
Hello Lagida,
The error message you’ve encountered typically indicates a discrepancy between the number of outcomes (target variable) and the number of features (predictor variables) in your dataset. You should verify that your data is properly formatted and organized to resolve this issue.
Here are some steps you can take to troubleshoot this problem:
Check your data: Ensure that the input data is structured correctly, with each row representing an observation and each column representing a feature. Ensure your target variable (Y) has the correct number of outcomes and your feature matrix (X) has the correct number of features.
Verify data types: Ensure that the data types of your variables are correct. For example, ensure that categorical variables are encoded as factors and numerical variables are encoded as numeric data types.
Check input parameters: Make sure that you have specified the correct input parameters for the ordered random forest function. This includes setting the appropriate values for the number of trees, the minimum number of samples per leaf, and any other tuning parameters specific to the function you are using.
Regards,
Cansu