Using the stop() function
The stop() function is used to indicate that something is wrong.
Latihan ini adalah bagian dari kursus
Defensive R Programming
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
# Stop the execution if ages are negative
mean_age <- function(ages) {
if(any(ages < ___)) {
___("You have negative ages!")
}
m <- mean(ages)
return(m)
}