[BioC] tryCatch: go on executing after a warning message

Martin Morgan mtmorgan at fhcrc.org
Sat Dec 12 14:44:23 CET 2009


Hi Javier --

Javier Pérez Florido wrote:
> Dear list,
> I have a code sample in which a single assignment is returned. What I
> want to do is to collect all warning messages found in the example (they
> are forced in this example) and to go on after a warning message is
> found. I've tried with invokeRestart function, but it doesn't work. Any
> tips??

?withCallingHandlers; there's an example on the help page.

  withCallingHandlers({ warning("A"); 1+2 }, warning = function(w) {})

Martin

> 
> testTryCatch<-function()
> {
>    myWarnings <- NULL
> 
>    tryCatch({
>            a<-3
>            b<-a+6
>            warning("hello1")
>            c<-6+13
>            warning("hello2")
>            return(c)
>    },warning=function(ex){
>         myWarnings <<- c(myWarnings, list(ex))            #some code
> (like invokeRestart("muffleWarning")) to go on executing in c<-6+13, but
> it doesn't work
>    },error=function(ex){
>        cat("error found")
>    },finally={
>        print(myWarnings)          }
>    )
> 
> }
> 
> Thanks,
> Javier
> 
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives:
> http://news.gmane.org/gmane.science.biology.informatics.conductor


-- 
Martin Morgan
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M1 B861
Phone: (206) 667-2793



More information about the Bioconductor mailing list