[R] argh .. if/else .. why?

Esmail esmail.js at gmail.com
Mon Feb 15 15:01:52 CET 2010


Hello, would someone please help explain the following inconsistency
in the  if/else statement to me?

The format of the if/else #3 below is ok, but if/else #1 is not? (I get
an "unexpected else" type error.) In order for it to work I have to use
if/else #2

Thanks .. maybe there is some reason for this, but this looks very
inconsistent to me.

R version 2.10.1 (2009-12-14)
Ubuntu 9.04

Esmail


---------------

#if (ZELIG)                                              ######## if/else #1
#  cat(sprintf("Zelig for %d runs - timeR\n", RUNS))
#else
#  cat(sprintf("lme for %d runs - timeR\n", RUNS))


if (ZELIG){                                              ####### if/else #2
   cat(sprintf("Zelig for %d runs - timeR\n", RUNS))
} else
{
   cat(sprintf("lme for %d runs - timeR\n", RUNS))
}


cat(date()," start - timeR\n")

for(i in 1:RUNS)
{

   if (ZELIG)                                              ##### if/else #3
     do_Zelig()
   else
     do_lme()


   cat(i, ' - ', date(),"\n")
}

cat(date()," end - timeR\n")
sink()



More information about the R-help mailing list