Get startedGet started for free

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

View Course

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)
}
Edit and Run Code