Re: [R] Conditionals for Errors or error flags

From: Ramon Diaz-Uriarte <>
Date: Sat, 15 Mar 2008 20:26:03 +0100

Dear Jon,

You probably want to take a look at "try" and "tryCatch". Either of them will let you do what you want.



On Sat, Mar 15, 2008 at 7:00 PM, Jon Loehrke <> wrote:
> Greetings,
> I have been working on a script that conducts repeated statistics and
> plots to my data. In this case it is sub-setting the dataframe by
> month.
> The intent is to develop a custom analysis and plotting that I can run
> on a large number of data sets.
> Unfortunately, a small portion of my subsets (~1%) cause an error with
> one of the wrapped subroutines that results in the whole routine
> aborting. It would be incredibly difficult to find the cause of this
> error post-run, and the particular routine does not have a way of
> treating the error (it isn't as simple as NA, etc.)
> What I am wondering is if there is a corollary to the conditional
> such as is.error()? Or is there a way to get some other output
> from an error than an abort?
> That I can use to toggle between a process that causes an error and
> one that doesn't without aborting the whole shebang.
> Any ideas are appreciated.
> I apologize that I could not think up an example so I included a
> psuedo-code below.
> do.something<-function(x){
> run other scripts with data, possibly causing an error
> }
> do.something.else<-function(x){
> Something that doesn't cause an error
> }
> run.prog<-function(x){
> if(IS.ERROR(do.something)){do.something.else}else{do.something} #or
> flag error
> }
> run.prog(data)
> #runs everything if there is an error it does not abort with error but
> rather does something else that doesn't error and continues.
> Thank you very much,
> Jon
> R 2.6.2
> MAC OS 10.5
> Jon Loehrke
> Graduate Research Assistant
> Department of Fisheries Oceanography
> School for Marine Science and Technology
> University of Massachusetts
> 200 Mill Road, Suite 325
> Fairhaven, MA 02719
> 508-758-6393
> ______________________________________________
> mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.

Ramon Diaz-Uriarte
Statistical Computing Team
Structural Biology and Biocomputing Programme
Spanish National Cancer Centre (CNIO)

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Sat 15 Mar 2008 - 19:32:04 GMT

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 Sat 15 Mar 2008 - 21:30:22 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive