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

Farrel Buchinsky fjbuch at gmail.com
Sat May 6 00:54:02 CEST 2006


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




More information about the R-help mailing list