Debugging
Computing for Data Analysis
1 / 1
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
2 / 1
Something’s Wrong!
Warning
> log(-1)
[1] NaN
Warning message:
In log(-1) : NaNs produced
3 / 1
Something’s 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
Something’s 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
Something’s 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
Something’s 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
本文档为【slides_debugging1】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。