Using the stop() function
The stop()
function is used to indicate that something is wrong.
This exercise is part of the course
Defensive R Programming
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Stop the execution if ages are negative
mean_age <- function(ages) {
if(any(ages < ___)) {
___("You have negative ages!")
}
m <- mean(ages)
return(m)
}