Re: [R] How to a handle an error in a loop

From: Berton Gunter <gunter.berton_at_gene.com>
Date: Sat 06 May 2006 - 09:01:39 EST


?try

as in

result<- try (some R expression...)
if (inherits(result,'try-error')) ...do something else ...do something else

Hope this allows you to get to heaven....

> -----Original Message-----
> From: r-help-bounces@stat.math.ethz.ch
> [mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Farrel
> Buchinsky
> Sent: Friday, May 05, 2006 3:54 PM
> To: r-help@stat.math.ethz.ch
> Subject: [R] How to a handle an error in a loop
>
> I am about one step away from heaven on earth. I think only one step!
> I am using dgc.genetics to run a TDT test on thousands of
> genetic loci. I
> have learnt (through the help of others on this mailing list)
> to send the
> complex output to useful data frames which in turn allow me
> to look at the
> big picture and screen the thousands of loci.
>
> Resultdt<-lapply(PGWide[,240:290], tdt)
> the above would do 51 loci at a time. I want to do 6000 all
> in one shot.
> the only problem is that about once every 100 variables in
> PGWide there is a
> locus whose data trips up the tdt function. And when it does,
> it short
> circuits the entire loop. Nothing gets written to Resultdt.
>
> > Resultdt<-lapply(PGWide[,240:389], tdt)
> Error in rep.default(1, nrow(U)) : rep() incorrect type for
> second argument
> In addition: Warning messages:
> 1: 1 misinheritances in: phase.resolve(g.cs, g.mr, g.fr,
> as.allele.pair =
> TRUE, allow.ambiguous = (parent ==
> 2: 1 misinheritances in: phase.resolve(g.cs, g.mr, g.fr,
> as.allele.pair =
> TRUE, allow.ambiguous = (parent ==
> 3: 4 misinheritances in: phase.resolve(g.cs, g.mr, g.fr,
> as.allele.pair =
> TRUE, allow.ambiguous = (parent ==
>
>
> It is very laborious working out which column it is that
> caused the error.
> But by narrowing down the range of the looping, one can do
> it. So eventually
> I got to:
>
> > tdt(PGWide[,243])
> Error in rep.default(1, nrow(U)) : rep() incorrect type for
> second argument
> In addition: Warning message:
> 4 misinheritances in: phase.resolve(g.cs, g.mr, g.fr,
> as.allele.pair = TRUE,
> allow.ambiguous = (parent ==
>
> Do I have to grapple with the code inside the tdt function in
> order to
> handle the error (disappointing because I only half
> understand the R code in
> it) or is there an easy way to instruct R to simply move onto
> the next one.
> I saw something about try() but it got me nowhere. I tried
> Resultdt<-lapply(PGWide[,385:389],try(tdt))
>
>
> --
> Farrel Buchinsky, MD
> Pediatric Otolaryngologist
> Allegheny General Hospital
> Pittsburgh, PA
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat May 06 09:06:57 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 09 May 2006 - 02:09:59 EST.

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