Is it possible to get a line number with an error report? I have a long script and an error: Error in `[.xts`(x, xsubset) : subscript out of bounds It would be very helpful, and save a lot of time, if there was some indication in the error message which line the error was. I can find it using binary search but that is a painful process. cheers Worik [[alternative HTML version deleted]]
One thing that I do when I have a long script is to put "progress" report messages. These have some comments so I can chart the progress and also print out the current CPU and memory usage so I can also isolate where potential problems might be. This will help narrow down the section of code where the error occurred. Are you also running with options(error=utils::recover) so that when the error occurs, you get the stack and current environment so that debugging is easier? On Fri, Nov 30, 2012 at 4:22 PM, Worik R <worikr at gmail.com> wrote:> Is it possible to get a line number with an error report? > > I have a long script and an error: > > Error in `[.xts`(x, xsubset) : subscript out of bounds > > > It would be very helpful, and save a lot of time, if there was some > indication in the error message which line the error was. > > I can find it using binary search but that is a painful process. > > cheers > Worik > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it.
On Nov 30, 2012, at 1:22 PM, Worik R wrote:> Is it possible to get a line number with an error report? > > I have a long script and an error: > > Error in `[.xts`(x, xsubset) : subscript out of bounds > > > It would be very helpful, and save a lot of time, if there was some > indication in the error message which line the error was. > > I can find it using binary search but that is a painful process.Generally if one is in an interactive mode, one is advised to use the error recovery process provided by: options(error=recover) You should then be dropped into the browser in the environment of the error. Execute ls() to see what variables are accessible in the local environment. So you also need to consult: ?browser -- David Winsemius, MD Alameda, CA, USA
On 12-11-30 4:22 PM, Worik R wrote:> Is it possible to get a line number with an error report?Yes, if the error occurs in code that has line number information. You get line number info by default if you use source(). If the error is deeply buried in code that doesn't have the info (as it may be in your case), then the suggestions to use options(error=recover) will offer you a stack trace that shows you which high level code called the function reporting the problem. Duncan Murdoch> > I have a long script and an error: > > Error in `[.xts`(x, xsubset) : subscript out of bounds > > > It would be very helpful, and save a lot of time, if there was some > indication in the error message which line the error was. > > I can find it using binary search but that is a painful process. > > cheers > Worik > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >