使用 stop() 函数
stop() 函数用于指示出现了问题。
本练习是课程的一部分
R 防御式编程
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Stop the execution if ages are negative
mean_age <- function(ages) {
if(any(ages < ___)) {
___("You have negative ages!")
}
m <- mean(ages)
return(m)
}stop() 函数用于指示出现了问题。
本练习是课程的一部分
通过完成这段示例代码来试试这个练习。
# Stop the execution if ages are negative
mean_age <- function(ages) {
if(any(ages < ___)) {
___("You have negative ages!")
}
m <- mean(ages)
return(m)
}