diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/FileConnections.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/FileConnections.java index b1717cbd0978c908ead547dead845cd767f7c277..548dc1d937d8a2e00b58475ca80bae1033ae074a 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/FileConnections.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/FileConnections.java @@ -229,9 +229,14 @@ public class FileConnections { */ final RCompression.Type cTypeActual; if (!raw && (openMode == AbstractOpenMode.Read || openMode == AbstractOpenMode.ReadBinary)) { - cTypeActual = RCompression.getCompressionType(base.path); - if (cTypeActual != cType) { + RCompression.Type cTypeFound = RCompression.getCompressionType(base.path); + // For binary reading force file's compression type if compression exists + // and it conflicts with requested compression type. + if (cTypeFound != cType && (openMode != AbstractOpenMode.ReadBinary || cType != RCompression.Type.NONE)) { + cTypeActual = cTypeFound; base.updateConnectionClass(mapConnectionClass(cTypeActual)); + } else { + cTypeActual = cType; } } else { cTypeActual = cType; 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 b6eaccf56c1109b3810b7015e7bd27b056114cfd..7c7844eec54af3ed8f929db16c05ba7670fdbe5a 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 @@ -72277,6 +72277,25 @@ Error: unexpected '}' in "{ .Internal(strrep(, '') }" [1] "" +##com.oracle.truffle.r.test.builtins.TestBuiltin_strsplit.testStrSplit# +#strsplit('a[1][1]=x11&a[1][2]=x12', '[[]') +[[1]] +[1] "a" "1]" "1]=x11&a" "1]" "2]=x12" + + +##com.oracle.truffle.r.test.builtins.TestBuiltin_strsplit.testStrSplit# +#strsplit('a[1][1]=x11&a[1][2]=x12', '[][]') +[[1]] +[1] "a" "1" "" "1" "=x11&a" "1" "" "2" +[9] "=x12" + + +##com.oracle.truffle.r.test.builtins.TestBuiltin_strsplit.testStrSplit# +#strsplit('a[1][1]=x11&a[1][2]=x12', ']') +[[1]] +[1] "a[1" "[1" "=x11&a[1" "[2" "=x12" + + ##com.oracle.truffle.r.test.builtins.TestBuiltin_strsplit.testStrSplit# #strsplit('foo bar baz', '[f z]', perl=TRUE) [[1]] @@ -85262,6 +85281,10 @@ Error in cat(x, file = file, sep = c(rep.int(sep, ncolumns - 1), "\n"), : [126] 00 00 02 00 04 00 09 00 00 00 01 61 00 04 00 09 00 00 00 01 62 00 00 00 fe [151] 00 00 00 fe +##com.oracle.truffle.r.test.library.base.TestConnections.testRawWriteBinary# +#f <- tempfile(); unlink(f); x <- 1:10; save(x, file=f); con <- file(f, 'rb'); dput(class(con)) +c("file", "connection") + ##com.oracle.truffle.r.test.library.base.TestConnections.testRawWriteBinary#Ignored.ImplementationError# #{ s <- "äöüß"; rc <- rawConnection(raw(0), "wb"); write(charToRaw(s), rc); res <- rawConnectionValue(rc); close(rc); res } [1] 63 33 20 61 34 20 63 33 20 62 36 20 63 33 0a 62 63 20 63 33 20 39 66 0a @@ -85461,6 +85484,12 @@ In readLines(zz, 2, warn = T, skipNul = F) : Warning message: In open.connection(con, "rb") : connection is already open +##com.oracle.truffle.r.test.library.base.TestConnections.testSeek# +#f1 <- file(open='w+b', encoding='UTF-8'); writeBin(charToRaw("abcd"), f1); seek(f1); seek(f1,0); seek(f1) +[1] 4 +[1] 4 +[1] 0 + ##com.oracle.truffle.r.test.library.base.TestConnections.testSeekTextConnection# #{ zz <- textConnection("Hello, World!"); res <- isSeekable(zz); close(zz); res } [1] FALSE diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestConnections.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestConnections.java index 9129f3984ce7819fe8cab6613e71cbff68706f4c..55b38976abe9eac9efc4ba341b4e395149f4331f 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestConnections.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestConnections.java @@ -247,6 +247,7 @@ public class TestConnections extends TestRBase { assertEval("conn <- rawConnection(raw(0), \"wb\"); value <- list(a=c(1,2,3), b='foo'); save(value, file=conn); rawConnectionValue(conn)"); // ignored because save refuses to write to a rawConnection that is not configured to binary assertEval(Ignored.ImplementationError, "conn <- rawConnection(raw(0), \"w\"); value <- c(1,2,3); save(value, file=conn); rawConnectionValue(conn)"); + assertEval("f <- tempfile(); unlink(f); x <- 1:10; save(x, file=f); con <- file(f, 'rb'); dput(class(con))"); } @Test