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!

How to Solve Error and Warning Messages in R


List of Typical Errors & Warnings in R (+ Examples)


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.



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!


Subscribe to the Statistics Globe Newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.

32 Comments. Leave new

  • Error: grouping factors must have > 1 sampled level

  • Error in make.names(col.names, unique = TRUE) :
    invalid multibyte string at ‘

  • 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)

    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:



      • 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?


  • 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 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?


  • (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?


  • 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?


  • 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


  • 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

  • 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

  • Error in `[<-.data.frame`(`*tmp*`, is.na(df$Ozone), "Ozone", value = c(41L, :
    replacement has 153 rows, data has 37

  • 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.


  • Hi Jaochim,

    I am unable to execute this piece of script in MacBook – I installed R studio Version 2023.09.1+494 (2023.09.1+494)

    install.packages(“data.table”) # Install & load data.table

    I am getting this error – Please do the needful.

    There is a binary version available but the source version is later:
    binary source needs_compilation
    data.table 1.14.2 1.14.8 TRUE

    Do you want to install from sources the package which needs compilation? (Yes/no/cancel) library(“data.table”)
    Error in install.packages : Unrecognized response “library(“data.table”)”

    Thanks in advance.

    Chandru S

    • Hello Chandru,

      When you see the prompt Do you want to install from sources the package which needs compilation? (Yes/no/cancel), you need to type one of the options (Yes, no, cancel) and then press Enter. Typing Yes will compile the package from source, which can take a longer time and requires you to have the appropriate compiling tools installed on your MacBook (like Xcode command-line tools). Typing no will install the binary version, which is quicker and does not require compilation.

      Only after the installation process has completed should you use the library function to load the package.


  • Hello Cansu,

    Thanks for your reply, I tried with commnd ‘Yes’ and ‘No’ and even ‘cancel’ it did not work. Now, I need to find the code. I’ll get back to you if I need any help from you.

    Much appreciated.

    Thank you.

  • 1: model fit failed for Fold01: maxdepth=1, mfinal=150 Error in imp[m, ] <- k[sort(row.names(k)), ] :
    number of items to replace is not a multiple of replacement length

    • Hello Somayyeh,

      The error message you’re encountering seems to be related to an issue in a machine learning or statistical model fitting process, specifically in a cross-validation or similar iterative procedure.

      Here’s a breakdown of the error message:

      “model fit failed for Fold01: maxdepth=1, mfinal=150”:
      This indicates that the model fitting process failed for the first fold in a cross-validation or similar iterative process.
      maxdepth=1 suggests that the maximum depth of the tree (if it’s a tree-based model like a decision tree or a gradient boosting machine) was set to 1.
      mfinal=150 might indicate the number of trees or iterations for an ensemble method like Gradient Boosting or Random Forest.

      “Error in imp[m, ] <- k[sort(row.names(k)), ]": This is a more specific error related to an assignment operation in R. It seems to be attempting to replace a subset of a matrix or a dataframe (imp[m, ]) with another subset (k[sort(row.names(k)), ]). The error message "number of items to replace is not a multiple of replacement length" typically occurs in R when the size of the object on the left side of the assignment (<-) does not match the size of the object on the right side. To address this issue, consider the following steps: Check Data Dimensions: Ensure that the dimensions of the data being used in each fold of the cross-validation match what the model expects. The error could be due to a mismatch in the number of rows or columns expected versus what is provided. Review Model Parameters: Double-check the parameters you're using for the model. If you're using an ensemble method, make sure the parameters like maxdepth and mfinal are appropriate for your data. Debugging the Code: If possible, run the model fitting process for just one fold and see if it succeeds. This might help isolate the issue. Consult Documentation: If you're using a specific R package for modeling, check its documentation for any known issues or requirements regarding data shape or model parameters. If these suggestions do not help then you can consult our Facebook discussion group: https://www.facebook.com/groups/statisticsglobe



Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.