Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8863349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:57:23+00:00 2026-06-14T15:57:23+00:00

Sometimes R throws me errors such as Error in if (ncol(x) != 2) {

  • 0

Sometimes R throws me errors such as

Error in if (ncol(x) != 2) { : argument is of length zero

with no additional information, when I’ve written no such code. Is there a general way for finding which function in which package causes an error?

Since most packages come compressed, it isn’t trivial to grep /usr/lib/R/library.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:57:25+00:00Added an answer on June 14, 2026 at 3:57 pm

    You can use traceback() to locate where the last error occurred. Usually it will point you to a call you make in your function. Then I typically put browser() at that point, run the function again and see what is going wrong.

    For example, here are two functions:

    f2 <- function(x)
    {
      if (x==1) "foo"
    }
    
    f <- function(x)
    {
      f2(x)
    }
    

    Note that f2() assumes an argument of length 1. We can misuse f:

    > f(NULL)
    Error in if (x == 1) "foo" : argument is of length zero
    

    Now we can use traceback() to locate what went wrong:

    > traceback()
    2: f2(x) at #3
    1: f(NULL)
    

    The number means how deep we are in the nested functions. So we see that f calls f2 and that gives an error at line 3. Pretty clear. We could reassign f with browser placed just before the f2 call now to check it’s input. browser() simply allows you to stop executing a function and look around in its environment. Similar to debug and debugonce except that you don’t have to execute every line up until the point you know something goes wrong.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I press F5 to reload my app sometimes throws errors and sometimes it
There are sometimes errors like this when using SQL Server: Transaction (Process ID 54)
In my JavaScript function sometimes $(args._postBackElement).valid() throws error because it is not a valid
I (new to VB.NET) am doing some code maintenance on a function that sometimes
Sometimes the exception type is unique enough to indicate the exact issue, such as
When I send an Ajax request in JavaScript (with JQuery), it sometimes throws an
I am facing a weird problem. My web application throws error Value to add
This is really an EF Code First question, but sometimes the context of OData
I've got some LINQ to SQL that sometimes throws a Cannot insert duplicate key
We allow users to write code which sometimes calls jQuery.ready(function(){..}) multiple times. It seems

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.