How to continue function when error is thrown in withCallingHandlers in R -


i'm writing test case r function tests whether error being thrown , caught correctly @ point in function , i'm having trouble getting test continue when error thrown during execution in withcallinghandlers(...). i'm using approach:

counter <- 0 withcallinghandlers({ testingfunction(df0, df1) testingfunction(df2, df3) testingfunction(df4, df5)  }, warning=function(war){     print(paste(war$message)) }, error=function(err){     print(paste(err$message))     if(err$message == paste("the function should throw error message",                               "at right time.")){         counter <<- counter + 1     }  })  stopifnot(counter == 2) 

the problem i'm running script exiting after first error (successfully) caught , i'm not sure how handle error after it's caught, withcallinghandlers continues onto next part of execution. understand has restart object i'm not sure how use them correctly. know how manipulate above code execution of withcallinghandlers(...) continues when error caught?

you can wrap each call testingfunction call trycatch.:

counter <- 0 testforexpectederror <- function(expr) {     trycatch(expr, error=function(err) {         print(paste(err$message))         if(err$message == paste("the function should throw error message",                                 "at right time.")){             counter <<- counter + 1         }     }) }  testforexpectederror(testingfunction(df0, df1)) testforexpectederror(testingfunction(df2, df3)) testforexpectederror(testingfunction(df4, df5))  stopifnot(counter == 2) 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -