Re: [Rd] error location

From: Thomas Lumley <tlumley_at_u.washington.edu>
Date: Fri 29 Sep 2006 - 13:51:02 GMT

On Fri, 29 Sep 2006, Peter Stencel wrote:

> Dear all,
>
> I've written a (quite long) function in R. While running it I get the
> following error message:
>
> Error in "[<-"(`*tmp*`, 1, 13, value =
> NULL) :
> number of items to replace is not a multiple of
> replacement length
> operation failed in: function () !!!
> evaluation not successful!!!
>
> How to interpret this error message? (There aren't any expressions that
> I'm using in my function.)
>
> How can I locate the error? Is it possible to do it with the command
> debug("functionname")?
>
> I'm new to R and I hope that someone can give me a piece of advice on
> finding errors. Thanks in advance.
>

The first step after you get an error is

   R> traceback()

This will give a stack trace, ie, it will show the function where the error occurred, the function that called it, the function that called it, and so on all the way up. At some point in the list there should be an expression that you recognize.

traceback() is often sufficient. When it isn't, the post-mortem debugger, which you use by setting options(error=recover), may help. After the error occurs this gives you the opportunity to run the debugger inside any of the functions that were executing. The debugger is basically an R prompt running inside the function, so you can do anything you could do in R. debug(f) starts the debugger whenever the function f() is called. This lets you get in before the error.

There is a section on debugging in the "Writing R Extensions" manual (in sufficiently recent versions of R).

         -thomas



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat Sep 30 00:04:09 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 29 Sep 2006 - 17:30:10 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.