To get into R debugging environment right before the function or line causing the problem in your script, insert “options(error=recover)”. Then go to your R Results folder and double click the .RData file. R will pop up and load the offending workspace. Then type “debugger()” at the prompt. You will get a bunch of numbered lines. They are the call stack. You can type a number to drill into the call stack to figure out what went wrong… here’s an example where my auclog value was NaN. I was expecting “Inf” or a number…
R version 2.10.1 (2009-12-14)
Copyright © 2009 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
[Previously saved workspace restored]
> debugger()
Message: Error in if (auclog == 0) { : missing value where TRUE/FALSE needed
Calls: by ... eval -> eval -> tapply -> lapply -> FUN -> FUN -> calcAUC
Available environments had calls:
1: by(df, subj, function(x, m) calcAUC(x = x, mauc = meth), meth)
2: by.data.frame(df, subj, function(x, m) calcAUC(x = x, mauc = meth), meth)
3: eval(substitute(tapply(1:nd, IND, FUNx, simplify = simplify)), data)
4: eval(expr, envir, enclos)
5: tapply(1:132, list(subj = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 7, 8,
6: lapply(split(X, group), FUN, ...)
7: FUN(X[[8]], ...)
8: FUN(data[x, , drop = FALSE], ...)
9: calcAUC(x = x, mauc = meth)
10: function ()
11: try(dump.frames())
12: tryCatch(expr, error = function(e) {
13: tryCatchList(expr, classes, parentenv, handlers)
14: tryCatchOne(expr, names, parentenv, handlers[[1]])
15: doTryCatch(return(expr), name, parentenv, handler)
Enter an environment number, or 0 to exit Selection: 9
Browsing in the environment with call:
calcAUC(x = x, mauc = meth)
Called from: debugger.look(ind)
Browse[1]> n
Available environments had calls:
1: by(df, subj, function(x, m) calcAUC(x = x, mauc = meth), meth)
2: by.data.frame(df, subj, function(x, m) calcAUC(x = x, mauc = meth), meth)
3: eval(substitute(tapply(1:nd, IND, FUNx, simplify = simplify)), data)
4: eval(expr, envir, enclos)
5: tapply(1:132, list(subj = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 7, 8,
6: lapply(split(X, group), FUN, ...)
7: FUN(X[[8]], ...)
8: FUN(data[x, , drop = FALSE], ...)
9: calcAUC(x = x, mauc = meth)
10: function ()
11: try(dump.frames())
12: tryCatch(expr, error = function(e) {
13: tryCatchList(expr, classes, parentenv, handlers)
14: tryCatchOne(expr, names, parentenv, handlers[[1]])
15: doTryCatch(return(expr), name, parentenv, handler)
Enter an environment number, or 0 to exit Selection: 9
Browsing in the environment with call:
calcAUC(x = x, mauc = meth)
Called from: debugger.look(ind)
Browse[1]> auclog
[1] NaN
Browse[1]> cp
[1] 0.00 3.05 3.05 7.31 7.56 6.59 5.88 4.73 4.57 3.00 1.25
Browse[1]> tm
[1] 0.00 0.25 0.52 0.98 2.02 3.53 5.05 7.15 9.07 12.10 24.12
Browse[1]> i
[1] 3
Browse[1]> n
Available environments had calls:
1: by(df, subj, function(x, m) calcAUC(x = x, mauc = meth), meth)
2: by.data.frame(df, subj, function(x, m) calcAUC(x = x, mauc = meth), meth)
3: eval(substitute(tapply(1:nd, IND, FUNx, simplify = simplify)), data)
4: eval(expr, envir, enclos)
5: tapply(1:132, list(subj = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 7, 8,
6: lapply(split(X, group), FUN, ...)
7: FUN(X[[8]], ...)
8: FUN(data[x, , drop = FALSE], ...)
9: calcAUC(x = x, mauc = meth)
10: function ()
11: try(dump.frames())
12: tryCatch(expr, error = function(e) {
13: tryCatchList(expr, classes, parentenv, handlers)
14: tryCatchOne(expr, names, parentenv, handlers[[1]])
15: doTryCatch(return(expr), name, parentenv, handler)
Enter an environment number, or 0 to exit Selection: 0
>