You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2019/03/25 22:05:27 UTC

[arrow] branch master updated: ARROW-5003: [R] remove dependency on withr

This is an automated email from the ASF dual-hosted git repository.

wesm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new 0536ef8  ARROW-5003: [R] remove dependency on withr
0536ef8 is described below

commit 0536ef8174982a7a13a251174cc38701e8663b68
Author: Romain Francois <ro...@purrple.cat>
AuthorDate: Mon Mar 25 17:05:17 2019 -0500

    ARROW-5003: [R] remove dependency on withr
    
    We were not using it all that much and needed a development version. I've rolled back to using `on.exit()`
    
    Author: Romain Francois <ro...@purrple.cat>
    
    Closes #4025 from romainfrancois/5003/withr and squashes the following commits:
    
    03981cb32 <Romain Francois> rm dependency on withr
    e15a473f3 <Romain Francois> remove unexported local_tempfile()
---
 r/DESCRIPTION                             |  4 ----
 r/NAMESPACE                               |  1 -
 r/R/Schema.R                              |  6 ++++--
 r/R/feather.R                             |  3 ++-
 r/R/on_exit.R                             | 28 ----------------------------
 r/R/read_record_batch.R                   |  6 ++++--
 r/R/read_table.R                          | 10 ++++++----
 r/R/write_arrow.R                         |  6 ++++--
 r/tests/testthat/test-Table.R             | 17 ++++++++++++-----
 r/tests/testthat/test-arrow-csv-.R        |  5 ++++-
 r/tests/testthat/test-compressed.R        |  7 +++++--
 r/tests/testthat/test-feather.R           | 23 ++++++++++++++++-------
 r/tests/testthat/test-read-write.R        |  6 ++++--
 r/tests/testthat/test-read_record_batch.R | 10 +++++++---
 14 files changed, 68 insertions(+), 64 deletions(-)

diff --git a/r/DESCRIPTION b/r/DESCRIPTION
index 83df256..7ffa8ce 100644
--- a/r/DESCRIPTION
+++ b/r/DESCRIPTION
@@ -26,10 +26,7 @@ Imports:
     fs,
     tibble,
     crayon,
-    withr,
     bit64
-Remotes:
-    r-lib/withr
 Roxygen: list(markdown = TRUE)
 RoxygenNote: 6.1.1
 Suggests:
@@ -61,7 +58,6 @@ Collate:
     'feather.R'
     'memory_pool.R'
     'message.R'
-    'on_exit.R'
     'parquet.R'
     'read_record_batch.R'
     'read_table.R'
diff --git a/r/NAMESPACE b/r/NAMESPACE
index b90c902..aba8bbc 100644
--- a/r/NAMESPACE
+++ b/r/NAMESPACE
@@ -178,5 +178,4 @@ importFrom(rlang,dots_n)
 importFrom(rlang,list2)
 importFrom(rlang,warn)
 importFrom(tibble,as_tibble)
-importFrom(withr,defer_parent)
 useDynLib(arrow, .registration = TRUE)
diff --git a/r/R/Schema.R b/r/R/Schema.R
index 08047a3..d57e274 100644
--- a/r/R/Schema.R
+++ b/r/R/Schema.R
@@ -81,12 +81,14 @@ read_schema <- function(stream, ...) {
 
 #' @export
 `read_schema.arrow::Buffer` <- function(stream, ...) {
-  stream <- close_on_exit(BufferReader(stream))
+  stream <- BufferReader(stream)
+  on.exit(stream$close())
   shared_ptr(`arrow::Schema`, ipc___ReadSchema_InputStream(stream))
 }
 
 #' @export
 `read_schema.raw` <- function(stream, ...) {
-  stream <- close_on_exit(BufferReader(stream))
+  stream <- BufferReader(stream)
+  on.exit(stream$close())
   shared_ptr(`arrow::Schema`, ipc___ReadSchema_InputStream(stream))
 }
diff --git a/r/R/feather.R b/r/R/feather.R
index eaeea4c..6e4b3a6 100644
--- a/r/R/feather.R
+++ b/r/R/feather.R
@@ -102,7 +102,8 @@ write_feather_RecordBatch <- function(data, stream) {
 #' @export
 #' @method write_feather_RecordBatch fs_path
 `write_feather_RecordBatch.fs_path` <- function(data, stream) {
-  file_stream <- close_on_exit(FileOutputStream(stream))
+  file_stream <- FileOutputStream(stream)
+  on.exit(file_stream$close())
   `write_feather_RecordBatch.arrow::io::OutputStream`(data, file_stream)
 }
 
diff --git a/r/R/on_exit.R b/r/R/on_exit.R
deleted file mode 100644
index 52b0174..0000000
--- a/r/R/on_exit.R
+++ /dev/null
@@ -1,28 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-#' @importFrom withr defer_parent
-close_on_exit <- function(x, ...){
-  defer_parent(x$close(), ...)
-  x
-}
-
-local_tempfile <- function(...){
-  tf <- tempfile()
-  defer_parent(unlink(tf), ...)
-  tf
-}
diff --git a/r/R/read_record_batch.R b/r/R/read_record_batch.R
index 967ac5b..cc57b44 100644
--- a/r/R/read_record_batch.R
+++ b/r/R/read_record_batch.R
@@ -41,12 +41,14 @@ read_record_batch <- function(obj, schema){
 
 #' @export
 read_record_batch.raw <- function(obj, schema){
-  stream <- close_on_exit(BufferReader(obj))
+  stream <- BufferReader(obj)
+  on.exit(stream$close())
   read_record_batch(stream, schema)
 }
 
 #' @export
 `read_record_batch.arrow::Buffer` <- function(obj, schema){
-  stream <- close_on_exit(BufferReader(obj))
+  stream <- BufferReader(obj)
+  on.exit(stream$close())
   read_record_batch(stream, schema)
 }
diff --git a/r/R/read_table.R b/r/R/read_table.R
index 260c50f..b471296 100644
--- a/r/R/read_table.R
+++ b/r/R/read_table.R
@@ -69,15 +69,17 @@ read_table.character <- function(stream){
 
 #' @export
 read_table.fs_path <- function(stream) {
-  stream <- close_on_exit(ReadableFile(stream))
-  batch_reader <- close_on_exit(RecordBatchFileReader(stream))
+  stream <- ReadableFile(stream)
+  on.exit(stream$close())
+  batch_reader <- RecordBatchFileReader(stream)
   shared_ptr(`arrow::Table`, Table__from_RecordBatchFileReader(batch_reader))
 }
 
 #' @export
 `read_table.raw` <- function(stream) {
-  stream <- close_on_exit(BufferReader(stream))
-  batch_reader <- close_on_exit(RecordBatchStreamReader(stream))
+  stream <- BufferReader(stream)
+  on.exit(stream$close())
+  batch_reader <- RecordBatchStreamReader(stream)
   shared_ptr(`arrow::Table`, Table__from_RecordBatchStreamReader(batch_reader))
 }
 
diff --git a/r/R/write_arrow.R b/r/R/write_arrow.R
index 5fc6847..b979569 100644
--- a/r/R/write_arrow.R
+++ b/r/R/write_arrow.R
@@ -66,8 +66,10 @@ write_arrow <- function(x, stream, ...) {
 `write_arrow.fs_path` <- function(x, stream, ...) {
   assert_that(length(stream) == 1L)
   x <- to_arrow(x)
-  file_stream <- close_on_exit(FileOutputStream(stream))
-  file_writer <- close_on_exit(RecordBatchFileWriter(file_stream, x$schema))
+  file_stream <- FileOutputStream(stream)
+  on.exit(file_stream$close())
+  file_writer <- RecordBatchFileWriter(file_stream, x$schema)
+  on.exit(file_writer$close(), add = TRUE, after = FALSE)
   write_arrow(x, file_writer, ...)
 }
 
diff --git a/r/tests/testthat/test-Table.R b/r/tests/testthat/test-Table.R
index 068b30f..346ce4a 100644
--- a/r/tests/testthat/test-Table.R
+++ b/r/tests/testthat/test-Table.R
@@ -25,7 +25,7 @@ test_that("read_table handles various input streams (ARROW-3450, ARROW-3505)", {
   )
   tab <- arrow::table(tbl)
 
-  tf <- local_tempfile()
+  tf <- tempfile()
   write_arrow(tab, tf)
 
   bytes <- write_arrow(tab, raw())
@@ -33,11 +33,15 @@ test_that("read_table handles various input streams (ARROW-3450, ARROW-3505)", {
   tab1 <- read_table(tf)
   tab2 <- read_table(fs::path_abs(tf))
 
-  readable_file <- close_on_exit(ReadableFile(tf))
-  tab3 <- read_table(close_on_exit(RecordBatchFileReader(readable_file)))
+  readable_file <- ReadableFile(tf)
+  file_reader1 <- RecordBatchFileReader(readable_file)
+  tab3 <- read_table(file_reader1)
+  readable_file$close()
 
-  mmap_file <- close_on_exit(mmap_open(tf))
-  tab4 <- read_table(close_on_exit(RecordBatchFileReader(mmap_file)))
+  mmap_file <- mmap_open(tf)
+  file_reader2 <- RecordBatchFileReader(mmap_file)
+  tab4 <- read_table(file_reader2)
+  mmap_file$close()
 
   tab5 <- read_table(bytes)
 
@@ -54,6 +58,9 @@ test_that("read_table handles various input streams (ARROW-3450, ARROW-3505)", {
   expect_equal(tab, tab5)
   expect_equal(tab, tab6)
   expect_equal(tab, tab7)
+
+  unlink(tf)
+
 })
 
 test_that("Table cast (ARROW-3741)", {
diff --git a/r/tests/testthat/test-arrow-csv-.R b/r/tests/testthat/test-arrow-csv-.R
index 2afd062..27b4d53 100644
--- a/r/tests/testthat/test-arrow-csv-.R
+++ b/r/tests/testthat/test-arrow-csv-.R
@@ -18,7 +18,8 @@
 context("arrow::csv::TableReader")
 
 test_that("Can read csv file", {
-  tf <- local_tempfile()
+  tf <- tempfile()
+
   write.csv(iris, tf, row.names = FALSE, quote = FALSE)
 
   tab1 <- read_csv_arrow(tf)
@@ -30,4 +31,6 @@ test_that("Can read csv file", {
   expect_equal(tab0, tab1)
   expect_equal(tab0, tab2)
   expect_equal(tab0, tab3)
+
+  unlink(tf)
 })
diff --git a/r/tests/testthat/test-compressed.R b/r/tests/testthat/test-compressed.R
index 5ed0df8..1157475 100644
--- a/r/tests/testthat/test-compressed.R
+++ b/r/tests/testthat/test-compressed.R
@@ -20,13 +20,13 @@ context("arrow::io::Compressed.*Stream")
 test_that("can write Buffer to CompressedOutputStream and read back in CompressedInputStream", {
   buf <- buffer(as.raw(sample(0:255, size = 1024, replace = TRUE)))
 
-  tf1 <- local_tempfile()
+  tf1 <- tempfile()
   stream1 <- CompressedOutputStream(tf1)
   stream1$write(buf)
   expect_error(stream1$tell())
   stream1$close()
 
-  tf2 <- local_tempfile()
+  tf2 <- tempfile()
   sink2 <- FileOutputStream(tf2)
   stream2 <- CompressedOutputStream(sink2)
   stream2$write(buf)
@@ -44,5 +44,8 @@ test_that("can write Buffer to CompressedOutputStream and read back in Compresse
 
   expect_equal(buf, buf1)
   expect_equal(buf, buf2)
+
+  unlink(tf1)
+  unlink(tf2)
 })
 
diff --git a/r/tests/testthat/test-feather.R b/r/tests/testthat/test-feather.R
index 23fdc58..f97348c 100644
--- a/r/tests/testthat/test-feather.R
+++ b/r/tests/testthat/test-feather.R
@@ -20,17 +20,18 @@ context("Feather")
 test_that("feather read/write round trip", {
   tib <- tibble::tibble(x = 1:10, y = rnorm(10), z = letters[1:10])
 
-  tf1 <- local_tempfile()
+  tf1 <- tempfile()
   write_feather(tib, tf1)
   expect_true(fs::file_exists(tf1))
 
-  tf2 <- fs::path_abs(local_tempfile())
+  tf2 <- fs::path_abs(tempfile())
   write_feather(tib, tf2)
   expect_true(fs::file_exists(tf2))
 
-  tf3 <- local_tempfile()
-  stream <- close_on_exit(FileOutputStream(tf3))
+  tf3 <- tempfile()
+  stream <- FileOutputStream(tf3)
   write_feather(tib, stream)
+  stream$close()
   expect_true(fs::file_exists(tf3))
 
   tab1 <- read_feather(tf1)
@@ -55,12 +56,16 @@ test_that("feather read/write round trip", {
   expect_equal(tib, tab3)
   expect_equal(tib, tab4)
   expect_equal(tib, tab5)
+
+  unlink(tf1)
+  unlink(tf2)
+  unlink(tf3)
 })
 
 test_that("feather handles columns = <names>", {
   tib <- tibble::tibble(x = 1:10, y = rnorm(10), z = letters[1:10])
 
-  tf1 <- local_tempfile()
+  tf1 <- tempfile()
   write_feather(tib, tf1)
   expect_true(fs::file_exists(tf1))
 
@@ -68,12 +73,14 @@ test_that("feather handles columns = <names>", {
   expect_is(tab1, "data.frame")
 
   expect_equal(tib[, c("x", "y")], as_tibble(tab1))
+
+  unlink(tf1)
 })
 
 test_that("feather handles columns = <integer>", {
   tib <- tibble::tibble(x = 1:10, y = rnorm(10), z = letters[1:10])
 
-  tf1 <- local_tempfile()
+  tf1 <- tempfile()
   write_feather(tib, tf1)
   expect_true(fs::file_exists(tf1))
 
@@ -81,12 +88,13 @@ test_that("feather handles columns = <integer>", {
   expect_is(tab1, "data.frame")
 
   expect_equal(tib[, c("x", "y")], as_tibble(tab1))
+  unlink(tf1)
 })
 
 test_that("feather read/write round trip", {
   tib <- tibble::tibble(x = 1:10, y = rnorm(10), z = letters[1:10])
 
-  tf1 <- local_tempfile()
+  tf1 <- tempfile()
   write_feather(tib, tf1)
   expect_true(fs::file_exists(tf1))
 
@@ -94,6 +102,7 @@ test_that("feather read/write round trip", {
   expect_is(tab1, "arrow::Table")
 
   expect_equal(tib, as_tibble(tab1))
+  unlink(tf1)
 })
 
 
diff --git a/r/tests/testthat/test-read-write.R b/r/tests/testthat/test-read-write.R
index ffc14eb..3fe07cd 100644
--- a/r/tests/testthat/test-read-write.R
+++ b/r/tests/testthat/test-read-write.R
@@ -84,11 +84,12 @@ test_that("arrow::table round trip", {
   for( i in seq_along(chunks_raw)){
     expect_equal(chunked_array_raw$chunk(i-1L), chunks_raw[[i]])
   }
-  tf <- local_tempfile()
+  tf <- tempfile()
   write_arrow(tbl, tf)
 
   res <- read_arrow(tf)
   expect_identical(tbl, res)
+  unlink(tf)
 })
 
 test_that("arrow::table round trip handles NA in integer and numeric", {
@@ -114,7 +115,7 @@ test_that("arrow::table round trip handles NA in integer and numeric", {
   expect_equal(tab$column(1)$type, float64())
   expect_equal(tab$column(2)$type, int8())
 
-  tf <- local_tempfile()
+  tf <- tempfile()
   write_arrow(tbl, tf)
 
   res <- read_arrow(tf)
@@ -122,5 +123,6 @@ test_that("arrow::table round trip handles NA in integer and numeric", {
   expect_true(is.na(res$int[1]))
   expect_true(is.na(res$dbl[6]))
   expect_true(is.na(res$dbl[10]))
+  unlink(tf)
 })
 
diff --git a/r/tests/testthat/test-read_record_batch.R b/r/tests/testthat/test-read_record_batch.R
index 8477b7a..2618fae 100644
--- a/r/tests/testthat/test-read_record_batch.R
+++ b/r/tests/testthat/test-read_record_batch.R
@@ -23,7 +23,7 @@ test_that("RecordBatchFileWriter / RecordBatchFileReader roundtrips", {
     lgl = sample(c(TRUE, FALSE, NA), 10, replace = TRUE),
     chr = letters[1:10]
   ))
-  tf <- local_tempfile()
+  tf <- tempfile()
 
   writer <- RecordBatchFileWriter(tf, tab$schema)
   expect_is(writer, "arrow::ipc::RecordBatchFileWriter")
@@ -39,6 +39,7 @@ test_that("RecordBatchFileWriter / RecordBatchFileReader roundtrips", {
   writer$close()
   tab3 <- read_table(tf)
   expect_equal(tab, tab3)
+  unlink(tf)
 })
 
 test_that("read_record_batch() handles (raw|Buffer|InputStream, Schema) (ARROW-3450, ARROW-3505)", {
@@ -53,7 +54,9 @@ test_that("read_record_batch() handles (raw|Buffer|InputStream, Schema) (ARROW-3
   raw <- batch$serialize()
   batch2 <- read_record_batch(raw, schema)
   batch3 <- read_record_batch(buffer(raw), schema)
-  batch4 <- read_record_batch(close_on_exit(BufferReader(raw)), schema)
+  stream <- BufferReader(raw)
+  batch4 <- read_record_batch(stream, schema)
+  stream$close()
 
   expect_equal(batch, batch2)
   expect_equal(batch, batch3)
@@ -65,9 +68,10 @@ test_that("read_record_batch() can handle (Message, Schema) parameters (ARROW-34
   schema <- batch$schema
 
   raw <- batch$serialize()
-  stream <- close_on_exit(BufferReader(raw))
+  stream <- BufferReader(raw)
 
   message <- read_message(stream)
   batch2 <- read_record_batch(message, schema)
   expect_equal(batch, batch2)
+  stream$close()
 })