diff --git a/src/main/java/org/math/R/AbstractR2jsSession.java b/src/main/java/org/math/R/AbstractR2jsSession.java index a49d56f..fee50c0 100644 --- a/src/main/java/org/math/R/AbstractR2jsSession.java +++ b/src/main/java/org/math/R/AbstractR2jsSession.java @@ -1237,19 +1237,7 @@ private static String addIfElseBrackets(String expr) { if(addIfBrackets) ifSb.append("}"); ifSb.append(" else "); - // If this is a "else if", "else" stop when the next "if" stop - // Otherwise "else" stop at the next "}" int stopElseStatement = getNextExpressionLastIndex(result, elseIndex, "}"); - int elseIfIdx = result.indexOf("else if", elseIndex); - if(elseIndex == elseIfIdx) { - int nextIdOpenBracket = result.indexOf("{", elseIndex); - int nextCloseBracket = result.indexOf("}", elseIndex); - if(nextCloseBracket2) { 3 } else { 4 }"), 3, epsilon); @@ -1418,6 +1419,13 @@ public void testIfFunction() throws RException, ScriptException { engine.eval("f8 <- function() {if(TRUE) if(FALSE) 34 else if(TRUE) 1 else 2}"); assertEquals(1,(Double) engine.eval( "f8()"), epsilon); + + engine.eval("f9 <- function() {if(FALSE) 12 else if(FALSE) 13 else if(TRUE) 14}"); + assertEquals(14,(Double) engine.eval( "f9()"), epsilon); + + engine.eval("f10 <- function() {if(FALSE) { 12 } else if(FALSE) { 13 } else if(TRUE) { 14 }}"); + assertEquals(14,(Double) engine.eval( "f10()"), epsilon); + } @Test