diff --git a/src/main/java/org/math/R/AbstractR2jsSession.java b/src/main/java/org/math/R/AbstractR2jsSession.java index 6c7743d..ce902dc 100644 --- a/src/main/java/org/math/R/AbstractR2jsSession.java +++ b/src/main/java/org/math/R/AbstractR2jsSession.java @@ -2307,7 +2307,7 @@ private static String replaceOperators(String expr) { // We consider differently the '-' operator in '2-3' to the '-' negative: '-3'. // So we replace -3 by î3 first, but 2-3 stays 2-3 - expr = expr.replaceAll("([\\[\\{\\(\\-\\\\=*\\/^;%+:,><&|ôâêŝĝ\\n]) *-", "$1 î"); + expr = expr.replaceAll("([\\[\\{\\(\\-\\\\=*\\/^;%+:,><&|ôâêŝĝ\\n]|return) *-", "$1 î"); String stoppingCharacters = "-=*/^;%+:,><&|ôâêŝĝ\n"; // all operators but 'î' expr = expr.replaceAll("[)]/", ") /"); diff --git a/src/test/java/org/math/R/R2jsSessionTest.java b/src/test/java/org/math/R/R2jsSessionTest.java index a96e8e9..df0bb86 100644 --- a/src/test/java/org/math/R/R2jsSessionTest.java +++ b/src/test/java/org/math/R/R2jsSessionTest.java @@ -1483,6 +1483,18 @@ public void testDecimalPoints() throws RException { assertEquals((Double) engine.eval("1e-31*1e-32"), 1e-63, 1e-75); //"normal" floating error of 1e-15 on multiplication } + @Test + public void testMinus() throws RException { + engine.eval("test <- function() { -100+100+5 }"); + assert (Double) engine.eval("test()") == 5.0; + assert (Double) engine.eval("-3 -4") == -7; + assert (Double) engine.eval(" -3 -4") == -7; + assert (Double) engine.eval("( -3 -4)") == -7; + assert (Double) engine.eval(" ( -3 -4)") == -7; + assert (Double) engine.eval(" { -3 -4}") == -7; + assert ((double[]) engine.eval(" [ -3 -4]"))[0] == -7; + } + // @Test // public void testEvaluationTime() throws RException, ScriptException, IOException { // String MATH_JS_FILE = "/org/math/R/math.js";