I am debugging code that gives several warnings, but I am trying to stop the code when I get a specific warning so that I can look at the environment.
For instance:
myfun <- function(){ warning("The wrong warning") warning("The right warning") print("The end of the function") } tryCatch(myfun(), warning = function(w){ if(grepl("right", w$message)){ stop("I have you now") } else { message(w$message) } })
I would like the function to stop at the “Correct Warning”, but the trick stops as soon as it receives its first warning. How can I skip warnings that are of no interest and stop at those that interest me?
source share