[R] R bug? (if-else problem in main program)

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Wed Nov 6 09:58:49 CET 2002


"Lorenz Gygax" <gygax at ifi.unizh.ch> writes:

> If you want to split this over several lines, you need curly braces:
> 
> a <- 1
> 
> if ( a == 1 ) {
>   print ('yes')
> } else {
>   print ('no')
> }

Yep. And it isn't a bug, but a design issue. In interactive mode we
print the result of an expression as soon as it is syntactically
complete, so upon seeing
 
> a <- 1 ; if ( a == 1 ) print("yes")
[1] "yes"

we assume that we are done with that statement. After all, the next
line might be completely unrelated, e.g. "b <- 2", so we cannot wait
and see whether it starts with "else". So you need to ensure somehow
that the line is not syntactically complete, using braces as above, or,
e.g.,

> a <- 1 ; if ( a == 1 ) print("yes") else
+ print("no")
[1] "yes"



-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list