Debugging
Diagnosing the problem
Something’s Wrong!
Indications that something’s not right.
- message: A generic notification/diagnostic message produced by the message function;
execution of the function continues. - warning: An indication that something is wrong but not necessarily fatal; execution of the
function continues; generated by the warning function - error: An indication that a fatal problem has occurred; execution stops; produced by the stop
function condition: A generic concept for indicating that something unexpected can occur; programmers can create their own conditions
Warning
>log(-1)
## Warning: NaNs produced
## [1] NaN
>printmessage <- function(x) {
if(x > 0)
print("x is greater than zero")
else
print("x is less than or equal to zero")
invisible(x)
}
printmessage <- function(x) {
if (x > 0)
print("x is greater than zero")
else print("x is less than or equal to zero")
invisible(x)
}
printmessage(1)
## [1] "x is greater than zero"
printmessage(NA)
## Error: missing value where TRUE/FALSE needed
How do you know that something is wrong with your function?