Using the stop() function
The stop() function is used to indicate that something is wrong.
Questo esercizio fa parte del corso
Defensive R Programming
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# Stop the execution if ages are negative
mean_age <- function(ages) {
if(any(ages < ___)) {
___("You have negative ages!")
}
m <- mean(ages)
return(m)
}