mardi 13 août 2019

Extract which condition within if() statement was met in R

Is it possible to extract which statement within if() was met in R keeping multiple conditions within the same if() statement?

Example:

cond1 <- TRUE
cond2 <- FALSE

if(cond1 & cond2){
  message("Both cond1 and cond2 are true!")
} else {
  # PRINT WHICH CONDITION WAS NOT MET FIRST
   message(some_code_here, "WAS NOT MET :(")
}

Aucun commentaire:

Enregistrer un commentaire