Loop interruption when warning is encountered with TryCatch in R -
i use trycatch
handle warnings , errors in order write log file , secure code. write log correctly cat
when trycatch
returns success or error problem loop execution stopped when warning encountered.
whitout trycatch
loop not interrupted warning()
not clear me what's happening here because warning should not beaks loop.
breaking loop when "warnings()" appear in r
loop not interrupted :
>list <- c(1:10) for(i in list){ warning(i)} warning: 1 warning: 2 warning: 3 warning: 4 warning: 5 warning: 6 warning: 7 warning: 8 warning: 9 warning: 10 >
loop interrupted :
>trycatch( { list <- c(1:10) for(i in list){ warning(i) } }, error=function(cond) { message("error: ", cond) }, warning=function(cond) { message("warning: ", cond) } ) warning: simplewarning in dotrycatch(return(expr), name, parentenv, handler): 1 >
thank you,
Comments
Post a Comment