CommencerCommencer gratuitement

Using the stop() function

The stop() function is used to indicate that something is wrong.

Cet exercice fait partie du cours

Defensive R Programming

Afficher le cours

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Stop the execution if ages are negative
mean_age <- function(ages) {
   if(any(ages < ___)) {
    ___("You have negative ages!")
  }
  
  m <- mean(ages)
  return(m)
}
Modifier et exécuter le code