From ligges at statistik.uni-dortmund.de  Tue Mar  6 19:33:36 2007
From: ligges at statistik.uni-dortmund.de (Uwe Ligges)
Date: Tue, 06 Mar 2007 19:33:36 +0100
Subject: [Rd] parse error with if else (PR#9551)
In-Reply-To: <20070306171521.CC6C25D5F7@slim.kubism.ku.dk>
References: <20070306171521.CC6C25D5F7@slim.kubism.ku.dk>
Message-ID: <45EDB400.1070206@statistik.uni-dortmund.de>



Stephanie.Mahevas at ifremer.fr wrote:
> Full_Name: Stephanie MAHEVAS
> Version: 2.4.1
> OS: Windows NT
> Submission from: (NULL) (134.246.55.50)
> 
> 
> 
> the two following instructions provide a synthax  error :
> 
> if ( 5 > 4 ) cat("ok1")
> else cat("ok2")

This is not a bug!

Since you are allowed to omit the else, R cannot know whether you want 
to provide it and thinks you have finished, since
     if ( 5 > 4 ) cat("ok1")
already is a valid and complete expression.
Therefore
     else cat("ok2")
is a *new* expression which obviously is not valid without if() before.

If you want that R looks at the whole at first, either do as below or 
make it a whole expression by putting it into braces as in:

{
     if ( 5 > 4 ) cat("ok1")
     else cat("ok2")
}


Uwe Ligges




> and
> 
> if ( 5 > 4 ){ cat("ok1")}
> else cat("ok2")
> 
> whereas these ones don't
> 
> if ( 5 > 4 ) cat("ok1") else cat("ok2")
> 
> and
> 
> if ( 5 > 4 ){ cat("ok1")
> }else cat("ok2")
> 
> It looks like a parser problem. If else is not on the same line as if or if the
> end of block statement of if } is not paste to else, else does not seem linked
> with if
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] parse error with if else (PR#9551)
Uwe Ligges