[R] Conditionals for Errors or error flags
Ramon Diaz-Uriarte
rdiaz02 at gmail.com
Sat Mar 15 20:26:03 CET 2008
Dear Jon,
You probably want to take a look at "try" and "tryCatch". Either of
them will let you do what you want.
Best,
R.
On Sat, Mar 15, 2008 at 7:00 PM, Jon Loehrke <jloehrke at umassd.edu> 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
> is.na() 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
> jloehrke at umassd.edu
> 508-758-6393
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Ramon Diaz-Uriarte
Statistical Computing Team
Structural Biology and Biocomputing Programme
Spanish National Cancer Centre (CNIO)
http://ligarto.org/rdiaz
More information about the R-help
mailing list