Friday, October 13, 2006

Debug in R

> message(log(-1))
Error in if (x > 0) { : missing value where logical needed
In addition: Warning message:
NaNs produced in: log(x)
> traceback()
1: message(log(-1))
Here, traceback shows in which function the error occurred.

> SS(1, x)
[1] 208.1661
But suppose we wanted to interact with SS and see how it operates line by line. We need to

ag SS for debugging:
> debug(SS)
The following R session shows how SS runs in the debugger:
> SS(1, x)
debugging in: SS(1, x)
debug: {
d <- x - mu d2 <- d^2 ss <- sum(d2) ss } Browse[1]> n
debug: d <- x - mu Browse[1]> n
debug: d2 <- d^2 Browse[1]> n
debug: ss <- sum(d2) Browse[1]> n
debug: ss
Browse[1]> n
exiting from: SS(1, x)
[1] 208.1661

ls()


http://www.biostat.jhsph.edu/~rpeng/docs/R-debug-tools.pdf

No comments:

Blog Archive