Re: [Rd] Resume processing after warning handler.

From: Martin Morgan <mtmorgan_at_fhcrc.org>
Date: Sat, 04 Feb 2012 07:37:19 -0800

On 02/03/2012 02:49 AM, Titus von der Malsburg wrote:
> Dear list!
>
> I have a script that processes a large number of data files. When one
> file fails to process correctly, I want the script to write a message
> and to continue with the next file. I achieved this with tryCatch:
>
> for (f in files)
> tryCatch({heavy.lifting(f)}, error=function(e) log.error.to.file(e))
>
> I also want to log warning messages and tried something like this:
>
> for (f in files)
> tryCatch({heavy.lifting(f)},
> warning=function(w) {log.warning.to.file(w)},
> error=function(e) {log.error.to.file(e)})
>
> Unfortunately, this aborts processing when a warning is generated. My
> question: how can I resume processing after I logged the warning as if
> nothing had happened? My understanding of the man page is that his is
> not possible with tryCatch but I'm not sure.

Hi Titus -- use withCallingHandlers to capture the warning, and invokeRestart() to continue after handling it.

withCallingHandlers({

     warning('oops')
     message('continuing')
}, warning=function(w) {
     message('handling: ', conditionMessage(w))
     invokeRestart("muffleWarning")

})

>
> Thanks for any suggestions!
>
> Titus
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

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

Location: M1-B861
Telephone: 206 667-2793

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Sat 04 Feb 2012 - 15:40:35 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 06 Feb 2012 - 13:30:13 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive