If you want to use try constructors, you can set parameters for warning. See Also ?options . Better use tryCatch() :
x <- function(i){ if (i < 10) warning("A warning") i } tt <- tryCatch(x(5),error=function(e) e, warning=function(w) w) tt2 <- tryCatch(x(15),error=function(e) e, warning=function(w) w) tt
To get both a result and a warning:
tryCatch(x(5),warning=function(w) return(list(x(5),w)))
Using try
op <- options(warn=2) tt <- try(x()) ifelse(is(tt,"try-error"),"There was a warning or an error","OK") options(op)
Joris Meys Oct 11 2018-10-10T00: 00Z
source share