Hello! I work with: R : Copyright 2006, The R Foundation for Statistical Computing Version 2.3.1 (2006-06-01) On Windows XP Professional (Version 2002) SP2 I think there is a bug in the conditional execution if (expr1) {expr2} else {expr3} If I try: "if (expr1) expr2 else expr3" it works well but when I put the expression expr2 and expr3 between {} I receive an error message like this one: "Erreur dans parse(file, n = -1, NULL, "?") : erreur de syntaxe ? la ligne 4: } 5: else" ...which translated in english gives: "Error in parse(file, n = -1, NULL, "?") : syntax error at the line 4: } 5: else" Maybe, there is something I don't understand. I should be very grateful if you would help me to solve this issue. Best regards, Xavier ___________________________ Xavier Barron 20, rue de la Pierre Lev?e 75011 Paris 0143381141 / 0675062109
On Tue, 18 Jul 2006, Xavier Barron wrote:> Hello! > > I work with: > > R : Copyright 2006, The R Foundation for > Statistical Computing > Version 2.3.1 (2006-06-01) > > On Windows XP Professional (Version 2002) SP2 > > I think there is a bug in the conditional > execution if (expr1) {expr2} else {expr3} > > If I try: > > "if (expr1) expr2 else expr3" > > it works well but when I put the expression expr2 > and expr3 between {} I receive an error message > like this one:It's not a bug. You need the } on the same line as the else if (expr1){ expr2 } else { expr3 } as otherwise R doesn't know there is going to be an 'else'. -thomas> "Erreur dans parse(file, n = -1, NULL, "?") : > erreur de syntaxe ? la ligne > 4: } > 5: else" > > ...which translated in english gives: > > "Error in parse(file, n = -1, NULL, "?") : syntax > error at the line > 4: } > 5: else" > > Maybe, there is something I don't understand. I > should be very grateful if you would help me to > solve this issue. > > Best regards, > > Xavier > > ___________________________ > Xavier Barron > 20, rue de la Pierre Lev?e > 75011 Paris > 0143381141 / 0675062109 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >Thomas Lumley Assoc. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle
Hi not at all works for me> a<-1 > b<-2 > if (a>b) {print("Hallo")} else {print("OK")}[1] "OK"> if (a<b) {print("Hallo")} else {print("OK")}[1] "Hallo">you probably started your else on new line e.g.> if (a<b) {print("Hallo")} {Error: syntax error in " if (a<b) {print("Hallo")} {"> if (a<b)+ {print("Hallo")} else + {print("OK")} [1] "Hallo">HTH Petr On 18 Jul 2006 at 17:43, Xavier Barron wrote: Date sent: Tue, 18 Jul 2006 17:43:42 +0200 (CEST) From: Xavier Barron <xbarron at yahoo.com> To: r-help at stat.math.ethz.ch Subject: [R] I think this is a bug> Hello! > > I work with: > > R : Copyright 2006, The R Foundation for > Statistical Computing > Version 2.3.1 (2006-06-01) > > On Windows XP Professional (Version 2002) SP2 > > I think there is a bug in the conditional > execution if (expr1) {expr2} else {expr3} > > If I try: > > "if (expr1) expr2 else expr3" > > it works well but when I put the expression expr2 > and expr3 between {} I receive an error message > like this one: > > "Erreur dans parse(file, n = -1, NULL, "?") : > erreur de syntaxe ? la ligne > 4: } > 5: else" > > ...which translated in english gives: > > "Error in parse(file, n = -1, NULL, "?") : syntax > error at the line > 4: } > 5: else" > > Maybe, there is something I don't understand. I > should be very grateful if you would help me to > solve this issue. > > Best regards, > > Xavier > > ___________________________ > Xavier Barron > 20, rue de la Pierre Lev?e > 75011 Paris > 0143381141 / 0675062109 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html and provide commented, > minimal, self-contained, reproducible code.Petr Pikal petr.pikal at precheza.cz