Is there a way I can get R to automatically enter the browser inside a user-defined function on the generation of an error? Specifically, I'm trying to debug this: Error in as.double.default(sapply(lis, FUN)) : (list) object cannot be coerced to double In addition: There were 38 warnings (use warnings() to see them)> traceback()8: as.double.default(sapply(lis, FUN)) 7: as.numeric(sapply(lis, FUN)) 6: numeric.sapply(function(x) { x at statistic0 }) On detection of the error, I would like browser() to be called at the level of numeric.sapply(), so that I can examine x. I'm wondering if this can be done by modifying the default error handling. Using try() with browser() didn't work. Thanks, David _____________________________ David Bickel http://davidbickel.com Research Scientist Pioneer Hi-Bred International Bioinformatics & Exploratory Research 7250 NW 62nd Ave., PO Box 552 Johnston, Iowa 50131-0552 515-334-4739 Tel 515-334-6634 Fax david.bickel at pioneer.com, bickel at prueba.info This communication is for use by the intended recipient and ...{{dropped}}
Have you tried options(error=recover)? On Tue, 31 Aug 2004, Bickel, David wrote:> Is there a way I can get R to automatically enter the browser inside a user-defined function on the generation of an error? Specifically, I'm trying to debug this: > > Error in as.double.default(sapply(lis, FUN)) : > (list) object cannot be coerced to double > In addition: There were 38 warnings (use warnings() to see them) > > traceback() > 8: as.double.default(sapply(lis, FUN)) > 7: as.numeric(sapply(lis, FUN)) > 6: numeric.sapply(function(x) { > x at statistic0 > }) > > On detection of the error, I would like browser() to be called at the > level of numeric.sapply(), so that I can examine x. I'm wondering if > this can be done by modifying the default error handling. Using try() > with browser() didn't work.-- 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
use options(error=recover), e.g.: > remove("x") NULL Warning message: remove: variable "x" was not found > (function() {x})() Error in (function() { : Object "x" not found > options(error=recover) > (function(y=1) {x})(2) Error in (function(y = 1) { : Object "x" not found Enter a frame number, or 0 to exit 1:(function(y = 1) { Selection: 1 Called from: eval(expr, envir, enclos) Browse[1]> y [1] 2 Browse[1]> Enter a frame number, or 0 to exit 1:(function(y = 1) { Selection: 0 > At Tuesday 11:26 AM 8/31/2004, Bickel, David wrote:>Is there a way I can get R to automatically enter the browser inside a >user-defined function on the generation of an error? Specifically, I'm >trying to debug this: > >Error in as.double.default(sapply(lis, FUN)) : > (list) object cannot be coerced to double >In addition: There were 38 warnings (use warnings() to see them) > > traceback() >8: as.double.default(sapply(lis, FUN)) >7: as.numeric(sapply(lis, FUN)) >6: numeric.sapply(function(x) { > x at statistic0 > }) > >On detection of the error, I would like browser() to be called at the >level of numeric.sapply(), so that I can examine x. I'm wondering if this >can be done by modifying the default error handling. Using try() with >browser() didn't work. > >Thanks, >David >_____________________________ >David Bickel http://davidbickel.com >Research Scientist >Pioneer Hi-Bred International >Bioinformatics & Exploratory Research >7250 NW 62nd Ave., PO Box 552 >Johnston, Iowa 50131-0552 >515-334-4739 Tel >515-334-6634 Fax >david.bickel at pioneer.com, bickel at prueba.info > > > >This communication is for use by the intended recipient and ...{{dropped}} > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html