What is wrong in the following nested if-else statements:

  if (Condition_1) {              # begin IF_1                  
     statement_1
     statement_2
     statement_3
     if (Condition_2) {                 # begin IF_2
        a<- a +1
     }                                       # end IF_2
     statement_4  
     statement_5
     statement_6
     statement_7
     if (Condition_3) {                # begin IF_2                                                 
        statement_8
     } else {                             # ELSE_2
        statement_9
        statement_10
     }                                      # end IF_2
  } else {                           # ELSE_1
      statement_11
  }                                   # end IF_1


It looks like R interpret does not like the above syntax. In fact in my script I have the following instructions:

  if (DonohoAplhaON){                                
      tms <<- xx[,"sampamp"]                               #EXTRACT SIGNAL AMPLITUDE
      tmsLen <<- length(tms)
      J <<- ilogb(tmsLen, base=2)
      if (logb(tmsLen, base=2)%%2 > 0) {
         J <<- J + 1
      }
      rm(xx)
      rawtms <- tms 
      X <- PreProcessor(tms,tmsLen,J)
      BestWavList <- FindBestWavelet (X,tmsLen,J,Step1NumHighScalesOFF)
      if (!is.null(BestWavList)) {                                                         #COMPUTE SIGNAL DONOHO-ALPHA
         features.mat[ns,"alpha"]<- CalcDonohoAlpha(rawtms,BestWavList$No,J,tmsLen,Step3NumHighScalesOFF,Step3AllCoefON)
      } else {
         cat("\n\n Could not compute Best Wavelet Basis for Signal: ",fln,"  Skip current signal! \n\n")
         next
     }
  } else {
      features.mat[ns,"alpha"] <- NA
  }

It keeps printing out an error referred to the second " } else {" as if it could not realize that the inner if-statement has been closed:

>      if(!is.null(BestWavList)) {                                                         #COMPUTE SIGNAL DONOHO-ALPHA
+         features.mat[ns,"alpha"]<- CalcDonohoAlpha(rawtms,BestWavList$No,J,tmsLen,Step3NumHighScalesOFF,Step3AllCoefON)
+      }else {
+         cat("\n\n Could not compute Best Wavelet Basis for Signal: ",fln,"  Skip current signal! \n\n")
+         next
+      }
>   }else {
Error: unexpected '}' in "  }"
>      features.mat[ns,"alpha"] <- NA
>   }
Error: unexpected '}' in "  }"


Thank you for clarifying my doubts
Maura




tutti i telefonini TIM!


	[[alternative HTML version deleted]]


