0% found this document useful (0 votes)
36 views

Debugging: Computing For Data Analysis

The document discusses debugging in computing. It defines different types of messages that can indicate problems: warnings for non-fatal issues, errors for fatal problems, and conditions for unexpected events. It shows examples of a warning generated from taking the log of a negative number, and errors that can occur when passing missing/NA values to functions that are not designed to handle them. The document demonstrates how to design functions to properly handle missing values using is.na() checks.

Uploaded by

verai1131
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Debugging: Computing For Data Analysis

The document discusses debugging in computing. It defines different types of messages that can indicate problems: warnings for non-fatal issues, errors for fatal problems, and conditions for unexpected events. It shows examples of a warning generated from taking the log of a negative number, and errors that can occur when passing missing/NA values to functions that are not designed to handle them. The document demonstrates how to design functions to properly handle missing values using is.na() checks.

Uploaded by

verai1131
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Debugging

Computing for Data Analysis

1/1

Somethings Wrong!

Indications that somethings not right message: A generic notication/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

2/1

Somethings Wrong!

Warning > log(-1) [1] NaN Warning message: In log(-1) : NaNs produced

3/1

Somethings Wrong

printmessage <- function(x) { if(x > 0) print("x is greater than zero") else print("x is less than or equal to zero") invisible(x) }

4/1

Somethings Wrong

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 in if (x > 0) { : missing value where TRUE/FALSE needed

5/1

Somethings Wrong!

printmessage2 <- function(x) { if(is.na(x)) print("x is a missing value!") else if(x > 0) print("x is greater than zero") else print("x is less than or equal to zero") invisible(x) }

6/1

Somethings Wrong!
printmessage2 <- function(x) { if(is.na(x)) print("x is a missing value!") else if(x > 0) print("x is greater than zero") else print("x is less than or equal to zero") invisible(x) } > x <- log(-1) Warning message: In log(-1) : NaNs produced > printmessage2(x) [1] "x is a missing value!"
7/1

You might also like