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

From: Farrel Buchinsky <fjbuch_at_gmail.com>
Date: Sat 06 May 2006 - 08:54:02 EST


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
Received on Sat May 06 09:03:22 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 Sat 06 May 2006 - 10:10:02 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.