R code debugging
On Tue, 9 Nov 2004, Timur Elzhov wrote:
it's quite difficult for me to find `Error:'s in my R code, because R does say about error itself, but say nothing about its location, say, string number and file with an error (which may be `source'd from another file). Are there any option for turning of the similar feature, or R can not do such a thing at all?
R code can be created dynamically by R code (called `computing on the language'), and in most cases the source code is not retained (and it is not used for execution). traceback() will always tell you the function in which the error occurred. If you write reasonably modular code that should suffice, but if not, use debug() on that function and single-step through it to find where the error occurs. Or set a suitable error handler: have you explored recover(), for example?
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595