diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/CompleteCases.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/CompleteCases.java index 1b7b81345c61a2dee531da2469918a904077780f..a906872082f8fb367e53f90a70af7c65a0b824ae 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/CompleteCases.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/CompleteCases.java @@ -106,56 +106,56 @@ public final class CompleteCases extends RExternalBuiltinNode { if (arg instanceof RPairList) { for (Object t = ((RPairList) arg).car(); t != RNull.instance; t = ((RPairList) t).cdr()) { Object entry = ((RPairList) t).car(); - iterateAbstractVectorContents(len, result, i, entry); + iterateAbstractVectorContents(len, result, entry); } } else if (arg instanceof RList) { RList list = (RList) arg; for (int entry = 0; entry < list.getLength(); entry++) { - iterateAbstractVectorContents(len, result, i, list.getDataAt(entry)); + iterateAbstractVectorContents(len, result, list.getDataAt(entry)); } } else { - iterateAbstractVectorContents(len, result, i, arg); + iterateAbstractVectorContents(len, result, arg); } } return RDataFactory.createLogicalVector(result, true); } - private void iterateAbstractVectorContents(int len, byte[] result, int i, Object obj) { + private void iterateAbstractVectorContents(int len, byte[] result, Object obj) { Object entry = RRuntime.asAbstractVector(obj); if (entry instanceof RAbstractIntVector) { RAbstractIntVector v = (RAbstractIntVector) entry; for (int e = 0; e < v.getLength(); e++) { if (RRuntime.isNA(v.getDataAt(e))) { - result[i % len] = RRuntime.LOGICAL_FALSE; + result[e % len] = RRuntime.LOGICAL_FALSE; } } } else if (entry instanceof RAbstractLogicalVector) { RAbstractLogicalVector v = (RAbstractLogicalVector) entry; for (int e = 0; e < v.getLength(); e++) { if (RRuntime.isNA(v.getDataAt(e))) { - result[i % len] = RRuntime.LOGICAL_FALSE; + result[e % len] = RRuntime.LOGICAL_FALSE; } } } else if (entry instanceof RAbstractDoubleVector) { RAbstractDoubleVector v = (RAbstractDoubleVector) entry; for (int e = 0; e < v.getLength(); e++) { if (Double.isNaN(v.getDataAt(e))) { - result[i % len] = RRuntime.LOGICAL_FALSE; + result[e % len] = RRuntime.LOGICAL_FALSE; } } } else if (entry instanceof RAbstractComplexVector) { RAbstractComplexVector v = (RAbstractComplexVector) entry; for (int e = 0; e < v.getLength(); e++) { if (Double.isNaN(v.getDataAt(e).getRealPart()) || Double.isNaN(v.getDataAt(e).getImaginaryPart())) { - result[i % len] = RRuntime.LOGICAL_FALSE; + result[e % len] = RRuntime.LOGICAL_FALSE; } } } else if (entry instanceof RAbstractStringVector) { RAbstractStringVector v = (RAbstractStringVector) entry; for (int e = 0; e < v.getLength(); e++) { if (RRuntime.isNA(v.getDataAt(e))) { - result[i % len] = RRuntime.LOGICAL_FALSE; + result[e % len] = RRuntime.LOGICAL_FALSE; } } } else { diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test index 2d053696ba7cd58aad5f2c0956c44d4046c54747..075e99fff0f8ade7cfdd63b759aec9473a763fed 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test @@ -138294,6 +138294,27 @@ Error: argument 'files' must be character #.Call(tools:::Rmd5, c("abc","xyz")) [1] NA NA +##com.oracle.truffle.r.test.library.stats.TestExternal_completecases.testCompleteCases# +#stats::complete.cases(data.frame(col1=c(1,2,NA), col2=c(1,2,3))) +[1] TRUE TRUE FALSE + +##com.oracle.truffle.r.test.library.stats.TestExternal_completecases.testCompleteCases# +#stats::complete.cases(data.frame(col1=c(1,2,NA), col2=c(1,2,3)), c(1,NA,2)) +[1] TRUE FALSE FALSE + +##com.oracle.truffle.r.test.library.stats.TestExternal_completecases.testCompleteCases# +#stats::complete.cases(data.frame(col1=c(1,2,NA), col2=c(1,2,3)), data.frame(col1=c(1,NA,3), col2=c(1,2,3))) +[1] TRUE FALSE FALSE + +##com.oracle.truffle.r.test.library.stats.TestExternal_completecases.testCompleteCases# +#stats::complete.cases(data.frame(col1=c(1,NA), col2=c(2,3)), matrix(c(1,NA,2,NA), nrow=2)) +[1] TRUE FALSE + +##com.oracle.truffle.r.test.library.stats.TestExternal_completecases.testCompleteCasesArgsValidation#Output.IgnoreErrorContext# +#stats::complete.cases(data.frame(col1=c(1,2,NA), col2=c(1,2,3)), list(NA,2,2)) +Error in stats::complete.cases(data.frame(col1 = c(1, 2, NA), col2 = c(1, : + not all arguments have the same length + ##com.oracle.truffle.r.test.library.stats.TestExternal_covcor.testCovcor# #.Call(stats:::C_cov, 1:5, 1:5, 4, FALSE) [1] 2.5 diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/stats/TestExternal_completecases.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/stats/TestExternal_completecases.java new file mode 100644 index 0000000000000000000000000000000000000000..a29b4977a7cc88634d440b2c2f75487c23256900 --- /dev/null +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/stats/TestExternal_completecases.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.oracle.truffle.r.test.library.stats; + +import org.junit.Test; + +import com.oracle.truffle.r.test.TestBase; + +public class TestExternal_completecases extends TestBase { + @Test + public void testCompleteCases() { + assertEval("stats::complete.cases(data.frame(col1=c(1,2,NA), col2=c(1,2,3)))"); + assertEval("stats::complete.cases(data.frame(col1=c(1,2,NA), col2=c(1,2,3)), data.frame(col1=c(1,NA,3), col2=c(1,2,3)))"); + assertEval("stats::complete.cases(data.frame(col1=c(1,2,NA), col2=c(1,2,3)), c(1,NA,2))"); + assertEval("stats::complete.cases(data.frame(col1=c(1,NA), col2=c(2,3)), matrix(c(1,NA,2,NA), nrow=2))"); + } + + @Test + public void testCompleteCasesArgsValidation() { + assertEval(Output.IgnoreErrorContext, "stats::complete.cases(data.frame(col1=c(1,2,NA), col2=c(1,2,3)), list(NA,2,2))"); + } +}