[R] cat bailing out in a for loop
Uwe Ligges
ligges at statistik.uni-dortmund.de
Tue Apr 5 17:33:55 CEST 2005
Federico Calboli wrote:
> Dear All,
>
> I am trying to calculate the Hardy-Weinberg Equilibrium p-value for 42
> SNPs. I am using the function HWE.exact from the package "genetics".
>
> In order not to do a lot of coding "by hand", I have a for loop that
> goes through each column (each column is one SNP) and gives me the
> p.value for HWE.exact. Unfortunately some SNP have reached fixation and
> HWE.exact requires a 2 alleles scenario.
>
> So my problem is that my for loop:
>
> ##################################################
>
> for (i in 1:42){
> xxx<-HWE.exact(genotype(laba.con[,i+3], sep=""))
> cat(colnames(laba)[i+3],xxx$p.value,"\n")}
>
> ##################################################
>
> bails out as soon as it hits a SNP at fixation for one allele, because
> HWE.exact fails.
>
> I have a lot of this game to play and checking things by hand is not
> idea, and I do not care about failed SNP, all I want is for the loop to
> carry on regardless of what's in xxx$p.value, even if HWE.exact failed
> to calculte it. Dump anything in there!
>
> Is there any way of forcing the loop to carry on?
See ?try.
Uwe Ligges
> Cheers,
>
> Federico Calboli
>
More information about the R-help
mailing list