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 b027f5a  ARROW-3350: [R] Wrap MemoryMappedFile class
b027f5a is described below

commit b027f5a0ea8bb3f6dcba3746c912e7257244349b
Author: Romain Francois <[email protected]>
AuthorDate: Thu Oct 11 11:55:42 2018 -0400

    ARROW-3350: [R] Wrap MemoryMappedFile class
    
    The functions `read_record_batch` and `read_table` become S3 generic and 
methods handle:
    
     - `arrow::io::RandomAccessFile` : that can be made with `file_open()` or 
`mmap_open()`
     - a file path (either a character scalar or a `fs::fs_path` object. In 
that case a `ReadableFile` stream is open, read from using the 
`arrow::io::RandomAccessFile` method and closed on exit.
     - `arrow::BufferReader`
     - a raw vector, which uses the `arrow::BufferReader` method
    
    Classes `Buffer`, `ReadableFile` and `MemoryMappedFile` are wrapped in R6 
classes.
    
    Author: Romain Francois <[email protected]>
    
    Closes #2714 from romainfrancois/ARROW-3350/MemoryMappedFile and squashes 
the following commits:
    
    4730a2809 <Romain Francois> +read_table methods for arrow::BufferReader and 
raw
    4c39da739 <Romain Francois> Move virtual methods higher
    9b99328b1 <Romain Francois> + read_record_batch.raw, 
read_record_batch.arrow::BufferReader
    7de16025d <Romain Francois> + buffer_reader and BufferReader
    4460d1f21 <Romain Francois> + buffer() function to create arrow::Buffer
    02c1cd82e <Romain Francois> + @javierluraschi as a ctb
    7f8d01bfc <Romain Francois> rebase
    b14e11a23 <Romain Francois> update FileMode enum
    5ed3222b7 <Romain Francois> linting
    171868408 <Romain Francois> read_table also becomes S3 generic
    276c9ecae <Romain Francois> read_record_batch S3 generic
    f582d031c <Romain Francois> + arrow::io::ReadableFile R6 class
    8c157b446 <Romain Francois> s/Seekable$Seek/MemoryMappedFile$Seek/
    938afcafa <Romain Francois> + Readable$Read(nbytes) -> Buffer
    0467422c6 <Romain Francois> wrapper R6 class for arrow::Buffer
    4596d7638 <Romain Francois> rename SimpleRBuffer -> arrow::r::RBuffer
    bb1d23fe2 <Romain Francois> + MemoryMappedFile$Open
    af96ac320 <Romain Francois> :baby: support for arrow::io::MemoryMappedFile
---
 r/DESCRIPTION                        |   3 +
 r/NAMESPACE                          |  24 +
 r/R/RcppExports.R                    | 268 +++++++----
 r/R/RecordBatch.R                    |  40 +-
 r/R/Table.R                          |  44 +-
 r/R/buffer.R                         |  59 +++
 r/R/enums.R                          |   6 +
 r/R/io.R                             |  95 ++++
 r/man/DataType.Rd                    |   3 +
 r/man/buffer.Rd                      |  17 +
 r/man/buffer_reader.Rd               |  14 +
 r/man/io.Rd                          |  24 +
 r/man/read_arrow.Rd                  |   4 +-
 r/man/read_record_batch.Rd           |  17 +
 r/man/read_table.Rd                  |  14 +
 r/src/RcppExports.cpp                | 833 ++++++++++++++++++++++-------------
 r/src/RecordBatch.cpp                |  39 +-
 r/src/Table.cpp                      |  50 ++-
 r/src/array.cpp                      |  19 +-
 r/src/arrow_types.h                  |  16 +
 r/src/buffer.cpp                     |  54 +++
 r/src/io.cpp                         | 109 +++++
 r/tests/testthat/test-RecordBatch.R  |  33 +-
 r/tests/testthat/test-Table.R        |  51 +++
 r/tests/testthat/test-buffer.R       |  39 ++
 r/tests/testthat/test-bufferreader.R |  40 ++
 26 files changed, 1470 insertions(+), 445 deletions(-)

diff --git a/r/DESCRIPTION b/r/DESCRIPTION
index 40253a8..ceab62a 100644
--- a/r/DESCRIPTION
+++ b/r/DESCRIPTION
@@ -3,6 +3,7 @@ Title: R Integration to 'Apache' 'Arrow'
 Version: 0.0.0.9000
 Authors@R: c(
     person("Romain", "François", email = "[email protected]", role = c("aut", 
"cre")),
+    person("Javier", "Luraschi", email = "[email protected]", role = 
c("ctb")),
     person("Apache Arrow", email = "[email protected]", role = c("aut", 
"cph"))
   )
 Description: R Integration to 'Apache' 'Arrow'.
@@ -46,7 +47,9 @@ Collate:
     'Struct.R'
     'Table.R'
     'array.R'
+    'buffer.R'
     'dictionary.R'
+    'io.R'
     'memory_pool.R'
     'reexports-tibble.R'
     'zzz.R'
diff --git a/r/NAMESPACE b/r/NAMESPACE
index cf5f226..649efe7 100644
--- a/r/NAMESPACE
+++ b/r/NAMESPACE
@@ -7,21 +7,41 @@ S3method("==","arrow::Field")
 S3method("==","arrow::RecordBatch")
 S3method(as_tibble,"arrow::RecordBatch")
 S3method(as_tibble,"arrow::Table")
+S3method(buffer,default)
+S3method(buffer,integer)
+S3method(buffer,numeric)
+S3method(buffer,raw)
+S3method(buffer_reader,"arrow::Buffer")
+S3method(buffer_reader,default)
 S3method(length,"arrow::Array")
 S3method(names,"arrow::RecordBatch")
 S3method(print,"arrow-enum")
+S3method(read_record_batch,"arrow::io::BufferReader")
+S3method(read_record_batch,"arrow::io::RandomAccessFile")
+S3method(read_record_batch,character)
+S3method(read_record_batch,fs_path)
+S3method(read_record_batch,raw)
+S3method(read_table,"arrow::io::BufferReader")
+S3method(read_table,"arrow::io::RandomAccessFile")
+S3method(read_table,character)
+S3method(read_table,fs_path)
+S3method(read_table,raw)
 export(DateUnit)
+export(FileMode)
 export(StatusCode)
 export(TimeUnit)
 export(Type)
 export(array)
 export(as_tibble)
 export(boolean)
+export(buffer)
+export(buffer_reader)
 export(chunked_array)
 export(date32)
 export(date64)
 export(decimal)
 export(dictionary)
+export(file_open)
 export(float16)
 export(float32)
 export(float64)
@@ -30,8 +50,12 @@ export(int32)
 export(int64)
 export(int8)
 export(list_of)
+export(mmap_create)
+export(mmap_open)
 export(null)
 export(read_arrow)
+export(read_record_batch)
+export(read_table)
 export(record_batch)
 export(schema)
 export(struct)
diff --git a/r/R/RcppExports.R b/r/R/RcppExports.R
index d8f63ed..8ca9fd6 100644
--- a/r/R/RcppExports.R
+++ b/r/R/RcppExports.R
@@ -1,6 +1,82 @@
 # Generated by using Rcpp::compileAttributes() -> do not edit by hand
 # Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
 
+Array__from_vector <- function(x) {
+    .Call(`_arrow_Array__from_vector`, x)
+}
+
+Array__as_vector <- function(array) {
+    .Call(`_arrow_Array__as_vector`, array)
+}
+
+Array__Slice1 <- function(array, offset) {
+    .Call(`_arrow_Array__Slice1`, array, offset)
+}
+
+Array__Slice2 <- function(array, offset, length) {
+    .Call(`_arrow_Array__Slice2`, array, offset, length)
+}
+
+Array__IsNull <- function(x, i) {
+    .Call(`_arrow_Array__IsNull`, x, i)
+}
+
+Array__IsValid <- function(x, i) {
+    .Call(`_arrow_Array__IsValid`, x, i)
+}
+
+Array__length <- function(x) {
+    .Call(`_arrow_Array__length`, x)
+}
+
+Array__offset <- function(x) {
+    .Call(`_arrow_Array__offset`, x)
+}
+
+Array__null_count <- function(x) {
+    .Call(`_arrow_Array__null_count`, x)
+}
+
+Array__type <- function(x) {
+    .Call(`_arrow_Array__type`, x)
+}
+
+Array__ToString <- function(x) {
+    .Call(`_arrow_Array__ToString`, x)
+}
+
+Array__type_id <- function(x) {
+    .Call(`_arrow_Array__type_id`, x)
+}
+
+Array__Equals <- function(lhs, rhs) {
+    .Call(`_arrow_Array__Equals`, lhs, rhs)
+}
+
+Array__ApproxEquals <- function(lhs, rhs) {
+    .Call(`_arrow_Array__ApproxEquals`, lhs, rhs)
+}
+
+Array__data <- function(array) {
+    .Call(`_arrow_Array__data`, array)
+}
+
+Array__RangeEquals <- function(self, other, start_idx, end_idx, 
other_start_idx) {
+    .Call(`_arrow_Array__RangeEquals`, self, other, start_idx, end_idx, 
other_start_idx)
+}
+
+Array__Mask <- function(array) {
+    .Call(`_arrow_Array__Mask`, array)
+}
+
+DictionaryArray__indices <- function(array) {
+    .Call(`_arrow_DictionaryArray__indices`, array)
+}
+
+DictionaryArray__dictionary <- function(array) {
+    .Call(`_arrow_DictionaryArray__dictionary`, array)
+}
+
 ArrayData__get_type <- function(x) {
     .Call(`_arrow_ArrayData__get_type`, x)
 }
@@ -17,6 +93,26 @@ ArrayData__get_offset <- function(x) {
     .Call(`_arrow_ArrayData__get_offset`, x)
 }
 
+Buffer__is_mutable <- function(buffer) {
+    .Call(`_arrow_Buffer__is_mutable`, buffer)
+}
+
+Buffer__ZeroPadding <- function(buffer) {
+    invisible(.Call(`_arrow_Buffer__ZeroPadding`, buffer))
+}
+
+Buffer__capacity <- function(buffer) {
+    .Call(`_arrow_Buffer__capacity`, buffer)
+}
+
+Buffer__size <- function(buffer) {
+    .Call(`_arrow_Buffer__size`, buffer)
+}
+
+r___RBuffer__initialize <- function(x) {
+    .Call(`_arrow_r___RBuffer__initialize`, x)
+}
+
 ChunkedArray__length <- function(chunked_array) {
     .Call(`_arrow_ChunkedArray__length`, chunked_array)
 }
@@ -257,6 +353,66 @@ DictionaryType__ordered <- function(type) {
     .Call(`_arrow_DictionaryType__ordered`, type)
 }
 
+Field__initialize <- function(name, type, nullable = TRUE) {
+    .Call(`_arrow_Field__initialize`, name, type, nullable)
+}
+
+Field__ToString <- function(type) {
+    .Call(`_arrow_Field__ToString`, type)
+}
+
+Field__name <- function(type) {
+    .Call(`_arrow_Field__name`, type)
+}
+
+Field__nullable <- function(type) {
+    .Call(`_arrow_Field__nullable`, type)
+}
+
+io___Readable__Read <- function(x, nbytes) {
+    .Call(`_arrow_io___Readable__Read`, x, nbytes)
+}
+
+io___InputStream__Close <- function(x) {
+    invisible(.Call(`_arrow_io___InputStream__Close`, x))
+}
+
+io___RandomAccessFile__GetSize <- function(x) {
+    .Call(`_arrow_io___RandomAccessFile__GetSize`, x)
+}
+
+io___RandomAccessFile__supports_zero_copy <- function(x) {
+    .Call(`_arrow_io___RandomAccessFile__supports_zero_copy`, x)
+}
+
+io___RandomAccessFile__Seek <- function(x, position) {
+    invisible(.Call(`_arrow_io___RandomAccessFile__Seek`, x, position))
+}
+
+io___RandomAccessFile__Tell <- function(x) {
+    .Call(`_arrow_io___RandomAccessFile__Tell`, x)
+}
+
+io___MemoryMappedFile__Create <- function(path, size) {
+    .Call(`_arrow_io___MemoryMappedFile__Create`, path, size)
+}
+
+io___MemoryMappedFile__Open <- function(path, mode) {
+    .Call(`_arrow_io___MemoryMappedFile__Open`, path, mode)
+}
+
+io___MemoryMappedFile__Resize <- function(x, size) {
+    invisible(.Call(`_arrow_io___MemoryMappedFile__Resize`, x, size))
+}
+
+io___ReadableFile__Open <- function(path) {
+    .Call(`_arrow_io___ReadableFile__Open`, path)
+}
+
+io___BufferReader__initialize <- function(buffer) {
+    .Call(`_arrow_io___BufferReader__initialize`, buffer)
+}
+
 MemoryPool__default <- function() {
     .Call(`_arrow_MemoryPool__default`)
 }
@@ -289,8 +445,12 @@ RecordBatch__to_dataframe <- function(batch) {
     .Call(`_arrow_RecordBatch__to_dataframe`, batch)
 }
 
-read_record_batch_ <- function(path) {
-    .Call(`_arrow_read_record_batch_`, path)
+read_record_batch_RandomAccessFile <- function(stream) {
+    .Call(`_arrow_read_record_batch_RandomAccessFile`, stream)
+}
+
+read_record_batch_BufferReader <- function(stream) {
+    .Call(`_arrow_read_record_batch_BufferReader`, stream)
 }
 
 RecordBatch__to_file <- function(batch, path) {
@@ -349,107 +509,23 @@ Table__to_file <- function(table, path) {
     .Call(`_arrow_Table__to_file`, table, path)
 }
 
-read_table_ <- function(path) {
-    .Call(`_arrow_read_table_`, path)
-}
-
-Table__to_dataframe <- function(table) {
-    .Call(`_arrow_Table__to_dataframe`, table)
-}
-
-Table__column <- function(table, i) {
-    .Call(`_arrow_Table__column`, table, i)
-}
-
-Array__from_vector <- function(x) {
-    .Call(`_arrow_Array__from_vector`, x)
-}
-
-Array__as_vector <- function(array) {
-    .Call(`_arrow_Array__as_vector`, array)
-}
-
-Array__Slice1 <- function(array, offset) {
-    .Call(`_arrow_Array__Slice1`, array, offset)
-}
-
-Array__Slice2 <- function(array, offset, length) {
-    .Call(`_arrow_Array__Slice2`, array, offset, length)
-}
-
-Array__IsNull <- function(x, i) {
-    .Call(`_arrow_Array__IsNull`, x, i)
-}
-
-Array__IsValid <- function(x, i) {
-    .Call(`_arrow_Array__IsValid`, x, i)
-}
-
-Array__length <- function(x) {
-    .Call(`_arrow_Array__length`, x)
+Table__to_stream <- function(table) {
+    .Call(`_arrow_Table__to_stream`, table)
 }
 
-Array__offset <- function(x) {
-    .Call(`_arrow_Array__offset`, x)
+read_table_RandomAccessFile <- function(stream) {
+    .Call(`_arrow_read_table_RandomAccessFile`, stream)
 }
 
-Array__null_count <- function(x) {
-    .Call(`_arrow_Array__null_count`, x)
+read_table_BufferReader <- function(stream) {
+    .Call(`_arrow_read_table_BufferReader`, stream)
 }
 
-Array__type <- function(x) {
-    .Call(`_arrow_Array__type`, x)
-}
-
-Array__ToString <- function(x) {
-    .Call(`_arrow_Array__ToString`, x)
-}
-
-Array__type_id <- function(x) {
-    .Call(`_arrow_Array__type_id`, x)
-}
-
-Array__Equals <- function(lhs, rhs) {
-    .Call(`_arrow_Array__Equals`, lhs, rhs)
-}
-
-Array__ApproxEquals <- function(lhs, rhs) {
-    .Call(`_arrow_Array__ApproxEquals`, lhs, rhs)
-}
-
-Array__data <- function(array) {
-    .Call(`_arrow_Array__data`, array)
-}
-
-Array__RangeEquals <- function(self, other, start_idx, end_idx, 
other_start_idx) {
-    .Call(`_arrow_Array__RangeEquals`, self, other, start_idx, end_idx, 
other_start_idx)
-}
-
-Array__Mask <- function(array) {
-    .Call(`_arrow_Array__Mask`, array)
-}
-
-DictionaryArray__indices <- function(array) {
-    .Call(`_arrow_DictionaryArray__indices`, array)
-}
-
-DictionaryArray__dictionary <- function(array) {
-    .Call(`_arrow_DictionaryArray__dictionary`, array)
-}
-
-Field__initialize <- function(name, type, nullable = TRUE) {
-    .Call(`_arrow_Field__initialize`, name, type, nullable)
-}
-
-Field__ToString <- function(type) {
-    .Call(`_arrow_Field__ToString`, type)
-}
-
-Field__name <- function(type) {
-    .Call(`_arrow_Field__name`, type)
+Table__to_dataframe <- function(table) {
+    .Call(`_arrow_Table__to_dataframe`, table)
 }
 
-Field__nullable <- function(type) {
-    .Call(`_arrow_Field__nullable`, type)
+Table__column <- function(table, i) {
+    .Call(`_arrow_Table__column`, table, i)
 }
 
diff --git a/r/R/RecordBatch.R b/r/R/RecordBatch.R
index af2a290..4e2e581 100644
--- a/r/R/RecordBatch.R
+++ b/r/R/RecordBatch.R
@@ -68,6 +68,42 @@ record_batch <- function(.data){
   `arrow::RecordBatch`$new(RecordBatch__from_dataframe(.data))
 }
 
-read_record_batch <- function(path){
-  `arrow::RecordBatch`$new(read_record_batch_(fs::path_abs(path)))
+#' Read a single record batch from a stream
+#'
+#' @param stream input stream
+#'
+#' @details `stream` can be a `arrow::io::RandomAccessFile` stream as created 
by [file_open()] or [mmap_open()] or a path.
+#'
+#' @export
+read_record_batch <- function(stream){
+  UseMethod("read_record_batch")
+}
+
+#' @export
+read_record_batch.character <- function(stream){
+  assert_that(length(stream) == 1L)
+  read_record_batch(fs::path_abs(stream))
+}
+
+#' @export
+read_record_batch.fs_path <- function(stream){
+  stream <- file_open(stream); on.exit(stream$Close())
+  read_record_batch(stream)
 }
+
+#' @export
+`read_record_batch.arrow::io::RandomAccessFile` <- function(stream){
+  `arrow::RecordBatch`$new(read_record_batch_RandomAccessFile(stream))
+}
+
+#' @export
+`read_record_batch.arrow::io::BufferReader` <- function(stream){
+  `arrow::RecordBatch`$new(read_record_batch_BufferReader(stream))
+}
+
+#' @export
+read_record_batch.raw <- function(stream){
+  stream <- buffer_reader(stream); on.exit(stream$Close())
+  read_record_batch(stream)
+}
+
diff --git a/r/R/Table.R b/r/R/Table.R
index a725c6e..8acf30d 100644
--- a/r/R/Table.R
+++ b/r/R/Table.R
@@ -23,6 +23,7 @@
     num_rows = function() Table__num_rows(self),
     schema = function() `arrow::Schema`$new(Table__schema(self)),
     to_file = function(path) invisible(Table__to_file(self, 
fs::path_abs(path))),
+    to_stream = function() Table__to_stream(self),
     column = function(i) `arrow::Column`$new(Table__column(self, i))
   )
 )
@@ -46,8 +47,41 @@ write_arrow <- function(data, path){
   table(data)$to_file(path)
 }
 
-read_table <- function(path){
-  `arrow::Table`$new(read_table_(fs::path_abs(path)))
+#' Read an arrow::Table from a stream
+#'
+#' @param stream stream. Either a stream created by [file_open()] or 
[mmap_open()] or a file path.
+#'
+#' @export
+read_table <- function(stream){
+  UseMethod("read_table")
+}
+
+#' @export
+read_table.character <- function(stream){
+  assert_that(length(stream) == 1L)
+  read_table(fs::path_abs(stream))
+}
+
+#' @export
+read_table.fs_path <- function(stream) {
+  stream <- file_open(stream); on.exit(stream$Close())
+  read_table(stream)
+}
+
+#' @export
+`read_table.arrow::io::RandomAccessFile` <- function(stream) {
+  `arrow::Table`$new(read_table_RandomAccessFile(stream))
+}
+
+#' @export
+`read_table.arrow::io::BufferReader` <- function(stream) {
+  `arrow::Table`$new(read_table_BufferReader(stream))
+}
+
+#' @export
+`read_table.raw` <- function(stream) {
+  stream <- buffer_reader(stream); on.exit(stream$Close())
+  read_table(stream)
 }
 
 #' @export
@@ -57,11 +91,11 @@ read_table <- function(path){
 
 #' Read an tibble from an arrow::Table on disk
 #'
-#' @param path binary arrow file
+#' @param stream input stream
 #'
 #' @return a [tibble::tibble]
 #'
 #' @export
-read_arrow <- function(path){
-  as_tibble(read_table(path))
+read_arrow <- function(stream){
+  as_tibble(read_table(stream))
 }
diff --git a/r/R/buffer.R b/r/R/buffer.R
new file mode 100644
index 0000000..6389fcb
--- /dev/null
+++ b/r/R/buffer.R
@@ -0,0 +1,59 @@
+# 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.
+
+#' @include R6.R
+#' @include enums.R
+
+`arrow::Buffer` <- R6Class("arrow::Buffer", inherit = `arrow::Object`,
+  public = list(
+    is_mutable = function() Buffer__is_mutable(self),
+    ZeroPadding = function() Buffer__ZeroPadding(self),
+    size = function() Buffer__size(self),
+    capacity = function() Buffer__capacity(self)
+  )
+)
+
+#' Create a buffer from an R object
+#'
+#' @param x R object
+#' @return an instance of `arrow::Buffer` that borrows memory from `x`
+#'
+#' @export
+buffer <- function(x){
+  UseMethod("buffer")
+}
+
+#' @export
+buffer.default <- function(x) {
+  stop("cannot convert to Buffer")
+}
+
+
+#' @export
+buffer.raw <- function(x) {
+  `arrow::Buffer`$new(r___RBuffer__initialize(x))
+}
+
+#' @export
+buffer.numeric <- function(x) {
+  `arrow::Buffer`$new(r___RBuffer__initialize(x))
+}
+
+#' @export
+buffer.integer <- function(x) {
+  `arrow::Buffer`$new(r___RBuffer__initialize(x))
+}
diff --git a/r/R/enums.R b/r/R/enums.R
index a491d52..6b4ff24 100644
--- a/r/R/enums.R
+++ b/r/R/enums.R
@@ -60,3 +60,9 @@ StatusCode <- enum("arrow::StatusCode",
   PlasmaObjectExists = 20L, PlasmaObjectNonexistent = 21L,
   PlasmaStoreFull = 22L, PlasmaObjectAlreadySealed = 23L
 )
+
+#' @rdname DataType
+#' @export
+FileMode <- enum("arrow::io::FileMode",
+  READ = 0L, WRITE = 1L, READWRITE = 2L
+)
diff --git a/r/R/io.R b/r/R/io.R
new file mode 100644
index 0000000..76fa1dc
--- /dev/null
+++ b/r/R/io.R
@@ -0,0 +1,95 @@
+# 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.
+
+#' @include R6.R
+#' @include enums.R
+#' @include buffer.R
+
+`arrow::io::Readable` <- R6Class("arrow::io::Readable", inherit = 
`arrow::Object`,
+  public = list(
+    Read = function(nbytes) `arrow::Buffer`$new(io___Readable__Read(self, 
nbytes))
+  )
+)
+
+`arrow::io::InputStream` <- R6Class("arrow::io::InputStream", inherit = 
`arrow::io::Readable`,
+  public = list(
+    Close = function() io___InputStream__Close(self)
+  )
+)
+
+`arrow::io::RandomAccessFile` <- R6Class("arrow::io::RandomAccessFile", 
inherit = `arrow::io::InputStream`,
+  public = list(
+    GetSize = function() io___RandomAccessFile__GetSize(self),
+    supports_zero_copy = function() 
io___RandomAccessFile__supports_zero_copy(self),
+    Seek = function(position) io___RandomAccessFile__Seek(self, position),
+    Tell = function() io___RandomAccessFile__Tell(self)
+  )
+)
+
+`arrow::io::MemoryMappedFile` <- R6Class("arrow::io::MemoryMappedFile", 
inherit = `arrow::io::RandomAccessFile`,
+  public = list(
+    Resize = function(size) io___MemoryMappedFile__Resize(self, size)
+  )
+)
+
+`arrow::io::ReadableFile` <- R6Class("arrow::io::ReadableFile", inherit = 
`arrow::io::RandomAccessFile`)
+`arrow::io::BufferReader` <- R6Class("arrow::io::BufferReader", inherit = 
`arrow::io::RandomAccessFile`)
+
+#' Create a new read/write memory mapped file of a given size
+#'
+#' @param path file path
+#' @param size size in bytes
+#' @param mode file mode (read/write/readwrite)
+#'
+#' @rdname io
+#' @export
+mmap_create <- `arrow::io::MemoryMappedFile`$create <- function(path, size) {
+  
`arrow::io::MemoryMappedFile`$new(io___MemoryMappedFile__Create(fs::path_abs(path),
 size))
+}
+
+#' @rdname io
+#' @export
+mmap_open <- `arrow::io::MemoryMappedFile`$open <- function(path, mode = 
c("read", "write", "readwrite")) {
+  mode <- match(match.arg(mode), c("read", "write", "readwrite")) - 1L
+  
`arrow::io::MemoryMappedFile`$new(io___MemoryMappedFile__Open(fs::path_abs(path),
 mode))
+}
+
+#' @rdname io
+#' @export
+file_open <- `arrow::io::ReadableFile`$open <- function(path) {
+  `arrow::io::ReadableFile`$new(io___ReadableFile__Open(fs::path_abs(path)))
+}
+
+#' Create a `arrow::BufferReader`
+#'
+#' @param x R object to treat as a buffer or a buffer created by [buffer()]
+#'
+#' @export
+buffer_reader <- function(x) {
+  UseMethod("buffer_reader")
+}
+
+#' @export
+`buffer_reader.arrow::Buffer` <- function(x) {
+  `arrow::io::BufferReader`$new(io___BufferReader__initialize(x))
+}
+
+#' @export
+buffer_reader.default <- function(x) {
+  buffer_reader(buffer(x))
+}
+
diff --git a/r/man/DataType.Rd b/r/man/DataType.Rd
index 92d959c..5063bbc 100644
--- a/r/man/DataType.Rd
+++ b/r/man/DataType.Rd
@@ -7,6 +7,7 @@
 \alias{DateUnit}
 \alias{Type}
 \alias{StatusCode}
+\alias{FileMode}
 \alias{int8}
 \alias{int16}
 \alias{int32}
@@ -41,6 +42,8 @@ Type
 
 StatusCode
 
+FileMode
+
 int8()
 
 int16()
diff --git a/r/man/buffer.Rd b/r/man/buffer.Rd
new file mode 100644
index 0000000..4d4e97e
--- /dev/null
+++ b/r/man/buffer.Rd
@@ -0,0 +1,17 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/buffer.R
+\name{buffer}
+\alias{buffer}
+\title{Create a buffer from an R object}
+\usage{
+buffer(x)
+}
+\arguments{
+\item{x}{R object}
+}
+\value{
+an instance of \code{arrow::Buffer} that borrows memory from \code{x}
+}
+\description{
+Create a buffer from an R object
+}
diff --git a/r/man/buffer_reader.Rd b/r/man/buffer_reader.Rd
new file mode 100644
index 0000000..3b814fb
--- /dev/null
+++ b/r/man/buffer_reader.Rd
@@ -0,0 +1,14 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/io.R
+\name{buffer_reader}
+\alias{buffer_reader}
+\title{Create a \code{arrow::BufferReader}}
+\usage{
+buffer_reader(x)
+}
+\arguments{
+\item{x}{R object to treat as a buffer or a buffer created by 
\code{\link[=buffer]{buffer()}}}
+}
+\description{
+Create a \code{arrow::BufferReader}
+}
diff --git a/r/man/io.Rd b/r/man/io.Rd
new file mode 100644
index 0000000..8c572d8
--- /dev/null
+++ b/r/man/io.Rd
@@ -0,0 +1,24 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/io.R
+\name{mmap_create}
+\alias{mmap_create}
+\alias{mmap_open}
+\alias{file_open}
+\title{Create a new read/write memory mapped file of a given size}
+\usage{
+mmap_create(path, size)
+
+mmap_open(path, mode = c("read", "write", "readwrite"))
+
+file_open(path)
+}
+\arguments{
+\item{path}{file path}
+
+\item{size}{size in bytes}
+
+\item{mode}{file mode (read/write/readwrite)}
+}
+\description{
+Create a new read/write memory mapped file of a given size
+}
diff --git a/r/man/read_arrow.Rd b/r/man/read_arrow.Rd
index 8fe7875..362ee7a 100644
--- a/r/man/read_arrow.Rd
+++ b/r/man/read_arrow.Rd
@@ -4,10 +4,10 @@
 \alias{read_arrow}
 \title{Read an tibble from an arrow::Table on disk}
 \usage{
-read_arrow(path)
+read_arrow(stream)
 }
 \arguments{
-\item{path}{binary arrow file}
+\item{stream}{input stream}
 }
 \value{
 a \link[tibble:tibble]{tibble::tibble}
diff --git a/r/man/read_record_batch.Rd b/r/man/read_record_batch.Rd
new file mode 100644
index 0000000..86e7673
--- /dev/null
+++ b/r/man/read_record_batch.Rd
@@ -0,0 +1,17 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/RecordBatch.R
+\name{read_record_batch}
+\alias{read_record_batch}
+\title{Read a single record batch from a stream}
+\usage{
+read_record_batch(stream)
+}
+\arguments{
+\item{stream}{input stream}
+}
+\description{
+Read a single record batch from a stream
+}
+\details{
+\code{stream} can be a \code{arrow::io::RandomAccessFile} stream as created by 
\code{\link[=file_open]{file_open()}} or \code{\link[=mmap_open]{mmap_open()}} 
or a path.
+}
diff --git a/r/man/read_table.Rd b/r/man/read_table.Rd
new file mode 100644
index 0000000..7b34654
--- /dev/null
+++ b/r/man/read_table.Rd
@@ -0,0 +1,14 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/Table.R
+\name{read_table}
+\alias{read_table}
+\title{Read an arrow::Table from a stream}
+\usage{
+read_table(stream)
+}
+\arguments{
+\item{stream}{stream. Either a stream created by 
\code{\link[=file_open]{file_open()}} or \code{\link[=mmap_open]{mmap_open()}} 
or a file path.}
+}
+\description{
+Read an arrow::Table from a stream
+}
diff --git a/r/src/RcppExports.cpp b/r/src/RcppExports.cpp
index 4ec9162..e98a432 100644
--- a/r/src/RcppExports.cpp
+++ b/r/src/RcppExports.cpp
@@ -6,6 +6,226 @@
 
 using namespace Rcpp;
 
+// Array__from_vector
+std::shared_ptr<arrow::Array> Array__from_vector(SEXP x);
+RcppExport SEXP _arrow_Array__from_vector(SEXP xSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< SEXP >::type x(xSEXP);
+    rcpp_result_gen = Rcpp::wrap(Array__from_vector(x));
+    return rcpp_result_gen;
+END_RCPP
+}
+// Array__as_vector
+SEXP Array__as_vector(const std::shared_ptr<arrow::Array>& array);
+RcppExport SEXP _arrow_Array__as_vector(SEXP arraySEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type array(arraySEXP);
+    rcpp_result_gen = Rcpp::wrap(Array__as_vector(array));
+    return rcpp_result_gen;
+END_RCPP
+}
+// Array__Slice1
+std::shared_ptr<arrow::Array> Array__Slice1(const 
std::shared_ptr<arrow::Array>& array, int offset);
+RcppExport SEXP _arrow_Array__Slice1(SEXP arraySEXP, SEXP offsetSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type array(arraySEXP);
+    Rcpp::traits::input_parameter< int >::type offset(offsetSEXP);
+    rcpp_result_gen = Rcpp::wrap(Array__Slice1(array, offset));
+    return rcpp_result_gen;
+END_RCPP
+}
+// Array__Slice2
+std::shared_ptr<arrow::Array> Array__Slice2(const 
std::shared_ptr<arrow::Array>& array, int offset, int length);
+RcppExport SEXP _arrow_Array__Slice2(SEXP arraySEXP, SEXP offsetSEXP, SEXP 
lengthSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type array(arraySEXP);
+    Rcpp::traits::input_parameter< int >::type offset(offsetSEXP);
+    Rcpp::traits::input_parameter< int >::type length(lengthSEXP);
+    rcpp_result_gen = Rcpp::wrap(Array__Slice2(array, offset, length));
+    return rcpp_result_gen;
+END_RCPP
+}
+// Array__IsNull
+bool Array__IsNull(const std::shared_ptr<arrow::Array>& x, int i);
+RcppExport SEXP _arrow_Array__IsNull(SEXP xSEXP, SEXP iSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type x(xSEXP);
+    Rcpp::traits::input_parameter< int >::type i(iSEXP);
+    rcpp_result_gen = Rcpp::wrap(Array__IsNull(x, i));
+    return rcpp_result_gen;
+END_RCPP
+}
+// Array__IsValid
+bool Array__IsValid(const std::shared_ptr<arrow::Array>& x, int i);
+RcppExport SEXP _arrow_Array__IsValid(SEXP xSEXP, SEXP iSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type x(xSEXP);
+    Rcpp::traits::input_parameter< int >::type i(iSEXP);
+    rcpp_result_gen = Rcpp::wrap(Array__IsValid(x, i));
+    return rcpp_result_gen;
+END_RCPP
+}
+// Array__length
+int Array__length(const std::shared_ptr<arrow::Array>& x);
+RcppExport SEXP _arrow_Array__length(SEXP xSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type x(xSEXP);
+    rcpp_result_gen = Rcpp::wrap(Array__length(x));
+    return rcpp_result_gen;
+END_RCPP
+}
+// Array__offset
+int Array__offset(const std::shared_ptr<arrow::Array>& x);
+RcppExport SEXP _arrow_Array__offset(SEXP xSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type x(xSEXP);
+    rcpp_result_gen = Rcpp::wrap(Array__offset(x));
+    return rcpp_result_gen;
+END_RCPP
+}
+// Array__null_count
+int Array__null_count(const std::shared_ptr<arrow::Array>& x);
+RcppExport SEXP _arrow_Array__null_count(SEXP xSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type x(xSEXP);
+    rcpp_result_gen = Rcpp::wrap(Array__null_count(x));
+    return rcpp_result_gen;
+END_RCPP
+}
+// Array__type
+std::shared_ptr<arrow::DataType> Array__type(const 
std::shared_ptr<arrow::Array>& x);
+RcppExport SEXP _arrow_Array__type(SEXP xSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type x(xSEXP);
+    rcpp_result_gen = Rcpp::wrap(Array__type(x));
+    return rcpp_result_gen;
+END_RCPP
+}
+// Array__ToString
+std::string Array__ToString(const std::shared_ptr<arrow::Array>& x);
+RcppExport SEXP _arrow_Array__ToString(SEXP xSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type x(xSEXP);
+    rcpp_result_gen = Rcpp::wrap(Array__ToString(x));
+    return rcpp_result_gen;
+END_RCPP
+}
+// Array__type_id
+arrow::Type::type Array__type_id(const std::shared_ptr<arrow::Array>& x);
+RcppExport SEXP _arrow_Array__type_id(SEXP xSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type x(xSEXP);
+    rcpp_result_gen = Rcpp::wrap(Array__type_id(x));
+    return rcpp_result_gen;
+END_RCPP
+}
+// Array__Equals
+bool Array__Equals(const std::shared_ptr<arrow::Array>& lhs, const 
std::shared_ptr<arrow::Array>& rhs);
+RcppExport SEXP _arrow_Array__Equals(SEXP lhsSEXP, SEXP rhsSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type lhs(lhsSEXP);
+    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type rhs(rhsSEXP);
+    rcpp_result_gen = Rcpp::wrap(Array__Equals(lhs, rhs));
+    return rcpp_result_gen;
+END_RCPP
+}
+// Array__ApproxEquals
+bool Array__ApproxEquals(const std::shared_ptr<arrow::Array>& lhs, const 
std::shared_ptr<arrow::Array>& rhs);
+RcppExport SEXP _arrow_Array__ApproxEquals(SEXP lhsSEXP, SEXP rhsSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type lhs(lhsSEXP);
+    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type rhs(rhsSEXP);
+    rcpp_result_gen = Rcpp::wrap(Array__ApproxEquals(lhs, rhs));
+    return rcpp_result_gen;
+END_RCPP
+}
+// Array__data
+std::shared_ptr<arrow::ArrayData> Array__data(const 
std::shared_ptr<arrow::Array>& array);
+RcppExport SEXP _arrow_Array__data(SEXP arraySEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type array(arraySEXP);
+    rcpp_result_gen = Rcpp::wrap(Array__data(array));
+    return rcpp_result_gen;
+END_RCPP
+}
+// Array__RangeEquals
+bool Array__RangeEquals(const std::shared_ptr<arrow::Array>& self, const 
std::shared_ptr<arrow::Array>& other, int start_idx, int end_idx, int 
other_start_idx);
+RcppExport SEXP _arrow_Array__RangeEquals(SEXP selfSEXP, SEXP otherSEXP, SEXP 
start_idxSEXP, SEXP end_idxSEXP, SEXP other_start_idxSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type self(selfSEXP);
+    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type other(otherSEXP);
+    Rcpp::traits::input_parameter< int >::type start_idx(start_idxSEXP);
+    Rcpp::traits::input_parameter< int >::type end_idx(end_idxSEXP);
+    Rcpp::traits::input_parameter< int >::type 
other_start_idx(other_start_idxSEXP);
+    rcpp_result_gen = Rcpp::wrap(Array__RangeEquals(self, other, start_idx, 
end_idx, other_start_idx));
+    return rcpp_result_gen;
+END_RCPP
+}
+// Array__Mask
+LogicalVector Array__Mask(const std::shared_ptr<arrow::Array>& array);
+RcppExport SEXP _arrow_Array__Mask(SEXP arraySEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type array(arraySEXP);
+    rcpp_result_gen = Rcpp::wrap(Array__Mask(array));
+    return rcpp_result_gen;
+END_RCPP
+}
+// DictionaryArray__indices
+std::shared_ptr<arrow::Array> DictionaryArray__indices(const 
std::shared_ptr<arrow::DictionaryArray>& array);
+RcppExport SEXP _arrow_DictionaryArray__indices(SEXP arraySEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const 
std::shared_ptr<arrow::DictionaryArray>& >::type array(arraySEXP);
+    rcpp_result_gen = Rcpp::wrap(DictionaryArray__indices(array));
+    return rcpp_result_gen;
+END_RCPP
+}
+// DictionaryArray__dictionary
+std::shared_ptr<arrow::Array> DictionaryArray__dictionary(const 
std::shared_ptr<arrow::DictionaryArray>& array);
+RcppExport SEXP _arrow_DictionaryArray__dictionary(SEXP arraySEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const 
std::shared_ptr<arrow::DictionaryArray>& >::type array(arraySEXP);
+    rcpp_result_gen = Rcpp::wrap(DictionaryArray__dictionary(array));
+    return rcpp_result_gen;
+END_RCPP
+}
 // ArrayData__get_type
 std::shared_ptr<arrow::DataType> ArrayData__get_type(const 
std::shared_ptr<arrow::ArrayData>& x);
 RcppExport SEXP _arrow_ArrayData__get_type(SEXP xSEXP) {
@@ -50,6 +270,60 @@ BEGIN_RCPP
     return rcpp_result_gen;
 END_RCPP
 }
+// Buffer__is_mutable
+bool Buffer__is_mutable(const std::shared_ptr<arrow::Buffer>& buffer);
+RcppExport SEXP _arrow_Buffer__is_mutable(SEXP bufferSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Buffer>& 
>::type buffer(bufferSEXP);
+    rcpp_result_gen = Rcpp::wrap(Buffer__is_mutable(buffer));
+    return rcpp_result_gen;
+END_RCPP
+}
+// Buffer__ZeroPadding
+void Buffer__ZeroPadding(const std::shared_ptr<arrow::Buffer>& buffer);
+RcppExport SEXP _arrow_Buffer__ZeroPadding(SEXP bufferSEXP) {
+BEGIN_RCPP
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Buffer>& 
>::type buffer(bufferSEXP);
+    Buffer__ZeroPadding(buffer);
+    return R_NilValue;
+END_RCPP
+}
+// Buffer__capacity
+int64_t Buffer__capacity(const std::shared_ptr<arrow::Buffer>& buffer);
+RcppExport SEXP _arrow_Buffer__capacity(SEXP bufferSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Buffer>& 
>::type buffer(bufferSEXP);
+    rcpp_result_gen = Rcpp::wrap(Buffer__capacity(buffer));
+    return rcpp_result_gen;
+END_RCPP
+}
+// Buffer__size
+int64_t Buffer__size(const std::shared_ptr<arrow::Buffer>& buffer);
+RcppExport SEXP _arrow_Buffer__size(SEXP bufferSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Buffer>& 
>::type buffer(bufferSEXP);
+    rcpp_result_gen = Rcpp::wrap(Buffer__size(buffer));
+    return rcpp_result_gen;
+END_RCPP
+}
+// r___RBuffer__initialize
+std::shared_ptr<arrow::Buffer> r___RBuffer__initialize(SEXP x);
+RcppExport SEXP _arrow_r___RBuffer__initialize(SEXP xSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< SEXP >::type x(xSEXP);
+    rcpp_result_gen = Rcpp::wrap(r___RBuffer__initialize(x));
+    return rcpp_result_gen;
+END_RCPP
+}
 // ChunkedArray__length
 int ChunkedArray__length(const std::shared_ptr<arrow::ChunkedArray>& 
chunked_array);
 RcppExport SEXP _arrow_ChunkedArray__length(SEXP chunked_arraySEXP) {
@@ -703,13 +977,182 @@ BEGIN_RCPP
     return rcpp_result_gen;
 END_RCPP
 }
-// MemoryPool__default
-std::shared_ptr<arrow::MemoryPool> MemoryPool__default();
-RcppExport SEXP _arrow_MemoryPool__default() {
+// Field__initialize
+std::shared_ptr<arrow::Field> Field__initialize(const std::string& name, const 
std::shared_ptr<arrow::DataType>& type, bool nullable);
+RcppExport SEXP _arrow_Field__initialize(SEXP nameSEXP, SEXP typeSEXP, SEXP 
nullableSEXP) {
 BEGIN_RCPP
     Rcpp::RObject rcpp_result_gen;
     Rcpp::RNGScope rcpp_rngScope_gen;
-    rcpp_result_gen = Rcpp::wrap(MemoryPool__default());
+    Rcpp::traits::input_parameter< const std::string& >::type name(nameSEXP);
+    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::DataType>& 
>::type type(typeSEXP);
+    Rcpp::traits::input_parameter< bool >::type nullable(nullableSEXP);
+    rcpp_result_gen = Rcpp::wrap(Field__initialize(name, type, nullable));
+    return rcpp_result_gen;
+END_RCPP
+}
+// Field__ToString
+std::string Field__ToString(const std::shared_ptr<arrow::Field>& type);
+RcppExport SEXP _arrow_Field__ToString(SEXP typeSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Field>& 
>::type type(typeSEXP);
+    rcpp_result_gen = Rcpp::wrap(Field__ToString(type));
+    return rcpp_result_gen;
+END_RCPP
+}
+// Field__name
+std::string Field__name(std::shared_ptr<arrow::Field> type);
+RcppExport SEXP _arrow_Field__name(SEXP typeSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< std::shared_ptr<arrow::Field> >::type 
type(typeSEXP);
+    rcpp_result_gen = Rcpp::wrap(Field__name(type));
+    return rcpp_result_gen;
+END_RCPP
+}
+// Field__nullable
+bool Field__nullable(std::shared_ptr<arrow::Field> type);
+RcppExport SEXP _arrow_Field__nullable(SEXP typeSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< std::shared_ptr<arrow::Field> >::type 
type(typeSEXP);
+    rcpp_result_gen = Rcpp::wrap(Field__nullable(type));
+    return rcpp_result_gen;
+END_RCPP
+}
+// io___Readable__Read
+std::shared_ptr<arrow::Buffer> io___Readable__Read(const 
std::shared_ptr<arrow::io::Readable>& x, int64_t nbytes);
+RcppExport SEXP _arrow_io___Readable__Read(SEXP xSEXP, SEXP nbytesSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::io::Readable>& 
>::type x(xSEXP);
+    Rcpp::traits::input_parameter< int64_t >::type nbytes(nbytesSEXP);
+    rcpp_result_gen = Rcpp::wrap(io___Readable__Read(x, nbytes));
+    return rcpp_result_gen;
+END_RCPP
+}
+// io___InputStream__Close
+void io___InputStream__Close(const std::shared_ptr<arrow::io::InputStream>& x);
+RcppExport SEXP _arrow_io___InputStream__Close(SEXP xSEXP) {
+BEGIN_RCPP
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const 
std::shared_ptr<arrow::io::InputStream>& >::type x(xSEXP);
+    io___InputStream__Close(x);
+    return R_NilValue;
+END_RCPP
+}
+// io___RandomAccessFile__GetSize
+int64_t io___RandomAccessFile__GetSize(const 
std::shared_ptr<arrow::io::RandomAccessFile>& x);
+RcppExport SEXP _arrow_io___RandomAccessFile__GetSize(SEXP xSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const 
std::shared_ptr<arrow::io::RandomAccessFile>& >::type x(xSEXP);
+    rcpp_result_gen = Rcpp::wrap(io___RandomAccessFile__GetSize(x));
+    return rcpp_result_gen;
+END_RCPP
+}
+// io___RandomAccessFile__supports_zero_copy
+bool io___RandomAccessFile__supports_zero_copy(const 
std::shared_ptr<arrow::io::RandomAccessFile>& x);
+RcppExport SEXP _arrow_io___RandomAccessFile__supports_zero_copy(SEXP xSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const 
std::shared_ptr<arrow::io::RandomAccessFile>& >::type x(xSEXP);
+    rcpp_result_gen = Rcpp::wrap(io___RandomAccessFile__supports_zero_copy(x));
+    return rcpp_result_gen;
+END_RCPP
+}
+// io___RandomAccessFile__Seek
+void io___RandomAccessFile__Seek(const 
std::shared_ptr<arrow::io::RandomAccessFile>& x, int64_t position);
+RcppExport SEXP _arrow_io___RandomAccessFile__Seek(SEXP xSEXP, SEXP 
positionSEXP) {
+BEGIN_RCPP
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const 
std::shared_ptr<arrow::io::RandomAccessFile>& >::type x(xSEXP);
+    Rcpp::traits::input_parameter< int64_t >::type position(positionSEXP);
+    io___RandomAccessFile__Seek(x, position);
+    return R_NilValue;
+END_RCPP
+}
+// io___RandomAccessFile__Tell
+int64_t io___RandomAccessFile__Tell(const 
std::shared_ptr<arrow::io::RandomAccessFile>& x);
+RcppExport SEXP _arrow_io___RandomAccessFile__Tell(SEXP xSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const 
std::shared_ptr<arrow::io::RandomAccessFile>& >::type x(xSEXP);
+    rcpp_result_gen = Rcpp::wrap(io___RandomAccessFile__Tell(x));
+    return rcpp_result_gen;
+END_RCPP
+}
+// io___MemoryMappedFile__Create
+std::shared_ptr<arrow::io::MemoryMappedFile> 
io___MemoryMappedFile__Create(const std::string& path, int64_t size);
+RcppExport SEXP _arrow_io___MemoryMappedFile__Create(SEXP pathSEXP, SEXP 
sizeSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const std::string& >::type path(pathSEXP);
+    Rcpp::traits::input_parameter< int64_t >::type size(sizeSEXP);
+    rcpp_result_gen = Rcpp::wrap(io___MemoryMappedFile__Create(path, size));
+    return rcpp_result_gen;
+END_RCPP
+}
+// io___MemoryMappedFile__Open
+std::shared_ptr<arrow::io::MemoryMappedFile> io___MemoryMappedFile__Open(const 
std::string& path, arrow::io::FileMode::type mode);
+RcppExport SEXP _arrow_io___MemoryMappedFile__Open(SEXP pathSEXP, SEXP 
modeSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const std::string& >::type path(pathSEXP);
+    Rcpp::traits::input_parameter< arrow::io::FileMode::type >::type 
mode(modeSEXP);
+    rcpp_result_gen = Rcpp::wrap(io___MemoryMappedFile__Open(path, mode));
+    return rcpp_result_gen;
+END_RCPP
+}
+// io___MemoryMappedFile__Resize
+void io___MemoryMappedFile__Resize(const 
std::shared_ptr<arrow::io::MemoryMappedFile>& x, int64_t size);
+RcppExport SEXP _arrow_io___MemoryMappedFile__Resize(SEXP xSEXP, SEXP 
sizeSEXP) {
+BEGIN_RCPP
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const 
std::shared_ptr<arrow::io::MemoryMappedFile>& >::type x(xSEXP);
+    Rcpp::traits::input_parameter< int64_t >::type size(sizeSEXP);
+    io___MemoryMappedFile__Resize(x, size);
+    return R_NilValue;
+END_RCPP
+}
+// io___ReadableFile__Open
+std::shared_ptr<arrow::io::ReadableFile> io___ReadableFile__Open(const 
std::string& path);
+RcppExport SEXP _arrow_io___ReadableFile__Open(SEXP pathSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const std::string& >::type path(pathSEXP);
+    rcpp_result_gen = Rcpp::wrap(io___ReadableFile__Open(path));
+    return rcpp_result_gen;
+END_RCPP
+}
+// io___BufferReader__initialize
+std::shared_ptr<arrow::io::BufferReader> io___BufferReader__initialize(const 
std::shared_ptr<arrow::Buffer>& buffer);
+RcppExport SEXP _arrow_io___BufferReader__initialize(SEXP bufferSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Buffer>& 
>::type buffer(bufferSEXP);
+    rcpp_result_gen = Rcpp::wrap(io___BufferReader__initialize(buffer));
+    return rcpp_result_gen;
+END_RCPP
+}
+// MemoryPool__default
+std::shared_ptr<arrow::MemoryPool> MemoryPool__default();
+RcppExport SEXP _arrow_MemoryPool__default() {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    rcpp_result_gen = Rcpp::wrap(MemoryPool__default());
     return rcpp_result_gen;
 END_RCPP
 }
@@ -791,14 +1234,25 @@ BEGIN_RCPP
     return rcpp_result_gen;
 END_RCPP
 }
-// read_record_batch_
-std::shared_ptr<arrow::RecordBatch> read_record_batch_(std::string path);
-RcppExport SEXP _arrow_read_record_batch_(SEXP pathSEXP) {
+// read_record_batch_RandomAccessFile
+std::shared_ptr<arrow::RecordBatch> read_record_batch_RandomAccessFile(const 
std::shared_ptr<arrow::io::RandomAccessFile>& stream);
+RcppExport SEXP _arrow_read_record_batch_RandomAccessFile(SEXP streamSEXP) {
 BEGIN_RCPP
     Rcpp::RObject rcpp_result_gen;
     Rcpp::RNGScope rcpp_rngScope_gen;
-    Rcpp::traits::input_parameter< std::string >::type path(pathSEXP);
-    rcpp_result_gen = Rcpp::wrap(read_record_batch_(path));
+    Rcpp::traits::input_parameter< const 
std::shared_ptr<arrow::io::RandomAccessFile>& >::type stream(streamSEXP);
+    rcpp_result_gen = Rcpp::wrap(read_record_batch_RandomAccessFile(stream));
+    return rcpp_result_gen;
+END_RCPP
+}
+// read_record_batch_BufferReader
+std::shared_ptr<arrow::RecordBatch> read_record_batch_BufferReader(const 
std::shared_ptr<arrow::io::BufferReader>& stream);
+RcppExport SEXP _arrow_read_record_batch_BufferReader(SEXP streamSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< const 
std::shared_ptr<arrow::io::BufferReader>& >::type stream(streamSEXP);
+    rcpp_result_gen = Rcpp::wrap(read_record_batch_BufferReader(stream));
     return rcpp_result_gen;
 END_RCPP
 }
@@ -964,312 +1418,92 @@ BEGIN_RCPP
     return rcpp_result_gen;
 END_RCPP
 }
-// read_table_
-std::shared_ptr<arrow::Table> read_table_(std::string path);
-RcppExport SEXP _arrow_read_table_(SEXP pathSEXP) {
-BEGIN_RCPP
-    Rcpp::RObject rcpp_result_gen;
-    Rcpp::RNGScope rcpp_rngScope_gen;
-    Rcpp::traits::input_parameter< std::string >::type path(pathSEXP);
-    rcpp_result_gen = Rcpp::wrap(read_table_(path));
-    return rcpp_result_gen;
-END_RCPP
-}
-// Table__to_dataframe
-List Table__to_dataframe(const std::shared_ptr<arrow::Table>& table);
-RcppExport SEXP _arrow_Table__to_dataframe(SEXP tableSEXP) {
+// Table__to_stream
+RawVector Table__to_stream(const std::shared_ptr<arrow::Table>& table);
+RcppExport SEXP _arrow_Table__to_stream(SEXP tableSEXP) {
 BEGIN_RCPP
     Rcpp::RObject rcpp_result_gen;
     Rcpp::RNGScope rcpp_rngScope_gen;
     Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Table>& 
>::type table(tableSEXP);
-    rcpp_result_gen = Rcpp::wrap(Table__to_dataframe(table));
-    return rcpp_result_gen;
-END_RCPP
-}
-// Table__column
-std::shared_ptr<arrow::Column> Table__column(const 
std::shared_ptr<arrow::Table>& table, int i);
-RcppExport SEXP _arrow_Table__column(SEXP tableSEXP, SEXP iSEXP) {
-BEGIN_RCPP
-    Rcpp::RObject rcpp_result_gen;
-    Rcpp::RNGScope rcpp_rngScope_gen;
-    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Table>& 
>::type table(tableSEXP);
-    Rcpp::traits::input_parameter< int >::type i(iSEXP);
-    rcpp_result_gen = Rcpp::wrap(Table__column(table, i));
+    rcpp_result_gen = Rcpp::wrap(Table__to_stream(table));
     return rcpp_result_gen;
 END_RCPP
 }
-// Array__from_vector
-std::shared_ptr<arrow::Array> Array__from_vector(SEXP x);
-RcppExport SEXP _arrow_Array__from_vector(SEXP xSEXP) {
+// read_table_RandomAccessFile
+std::shared_ptr<arrow::Table> read_table_RandomAccessFile(const 
std::shared_ptr<arrow::io::RandomAccessFile>& stream);
+RcppExport SEXP _arrow_read_table_RandomAccessFile(SEXP streamSEXP) {
 BEGIN_RCPP
     Rcpp::RObject rcpp_result_gen;
     Rcpp::RNGScope rcpp_rngScope_gen;
-    Rcpp::traits::input_parameter< SEXP >::type x(xSEXP);
-    rcpp_result_gen = Rcpp::wrap(Array__from_vector(x));
-    return rcpp_result_gen;
-END_RCPP
-}
-// Array__as_vector
-SEXP Array__as_vector(const std::shared_ptr<arrow::Array>& array);
-RcppExport SEXP _arrow_Array__as_vector(SEXP arraySEXP) {
-BEGIN_RCPP
-    Rcpp::RObject rcpp_result_gen;
-    Rcpp::RNGScope rcpp_rngScope_gen;
-    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type array(arraySEXP);
-    rcpp_result_gen = Rcpp::wrap(Array__as_vector(array));
-    return rcpp_result_gen;
-END_RCPP
-}
-// Array__Slice1
-std::shared_ptr<arrow::Array> Array__Slice1(const 
std::shared_ptr<arrow::Array>& array, int offset);
-RcppExport SEXP _arrow_Array__Slice1(SEXP arraySEXP, SEXP offsetSEXP) {
-BEGIN_RCPP
-    Rcpp::RObject rcpp_result_gen;
-    Rcpp::RNGScope rcpp_rngScope_gen;
-    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type array(arraySEXP);
-    Rcpp::traits::input_parameter< int >::type offset(offsetSEXP);
-    rcpp_result_gen = Rcpp::wrap(Array__Slice1(array, offset));
+    Rcpp::traits::input_parameter< const 
std::shared_ptr<arrow::io::RandomAccessFile>& >::type stream(streamSEXP);
+    rcpp_result_gen = Rcpp::wrap(read_table_RandomAccessFile(stream));
     return rcpp_result_gen;
 END_RCPP
 }
-// Array__Slice2
-std::shared_ptr<arrow::Array> Array__Slice2(const 
std::shared_ptr<arrow::Array>& array, int offset, int length);
-RcppExport SEXP _arrow_Array__Slice2(SEXP arraySEXP, SEXP offsetSEXP, SEXP 
lengthSEXP) {
+// read_table_BufferReader
+std::shared_ptr<arrow::Table> read_table_BufferReader(const 
std::shared_ptr<arrow::io::BufferReader>& stream);
+RcppExport SEXP _arrow_read_table_BufferReader(SEXP streamSEXP) {
 BEGIN_RCPP
     Rcpp::RObject rcpp_result_gen;
     Rcpp::RNGScope rcpp_rngScope_gen;
-    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type array(arraySEXP);
-    Rcpp::traits::input_parameter< int >::type offset(offsetSEXP);
-    Rcpp::traits::input_parameter< int >::type length(lengthSEXP);
-    rcpp_result_gen = Rcpp::wrap(Array__Slice2(array, offset, length));
+    Rcpp::traits::input_parameter< const 
std::shared_ptr<arrow::io::BufferReader>& >::type stream(streamSEXP);
+    rcpp_result_gen = Rcpp::wrap(read_table_BufferReader(stream));
     return rcpp_result_gen;
 END_RCPP
 }
-// Array__IsNull
-bool Array__IsNull(const std::shared_ptr<arrow::Array>& x, int i);
-RcppExport SEXP _arrow_Array__IsNull(SEXP xSEXP, SEXP iSEXP) {
+// Table__to_dataframe
+List Table__to_dataframe(const std::shared_ptr<arrow::Table>& table);
+RcppExport SEXP _arrow_Table__to_dataframe(SEXP tableSEXP) {
 BEGIN_RCPP
     Rcpp::RObject rcpp_result_gen;
     Rcpp::RNGScope rcpp_rngScope_gen;
-    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type x(xSEXP);
-    Rcpp::traits::input_parameter< int >::type i(iSEXP);
-    rcpp_result_gen = Rcpp::wrap(Array__IsNull(x, i));
+    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Table>& 
>::type table(tableSEXP);
+    rcpp_result_gen = Rcpp::wrap(Table__to_dataframe(table));
     return rcpp_result_gen;
 END_RCPP
 }
-// Array__IsValid
-bool Array__IsValid(const std::shared_ptr<arrow::Array>& x, int i);
-RcppExport SEXP _arrow_Array__IsValid(SEXP xSEXP, SEXP iSEXP) {
+// Table__column
+std::shared_ptr<arrow::Column> Table__column(const 
std::shared_ptr<arrow::Table>& table, int i);
+RcppExport SEXP _arrow_Table__column(SEXP tableSEXP, SEXP iSEXP) {
 BEGIN_RCPP
     Rcpp::RObject rcpp_result_gen;
     Rcpp::RNGScope rcpp_rngScope_gen;
-    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type x(xSEXP);
+    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Table>& 
>::type table(tableSEXP);
     Rcpp::traits::input_parameter< int >::type i(iSEXP);
-    rcpp_result_gen = Rcpp::wrap(Array__IsValid(x, i));
-    return rcpp_result_gen;
-END_RCPP
-}
-// Array__length
-int Array__length(const std::shared_ptr<arrow::Array>& x);
-RcppExport SEXP _arrow_Array__length(SEXP xSEXP) {
-BEGIN_RCPP
-    Rcpp::RObject rcpp_result_gen;
-    Rcpp::RNGScope rcpp_rngScope_gen;
-    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type x(xSEXP);
-    rcpp_result_gen = Rcpp::wrap(Array__length(x));
-    return rcpp_result_gen;
-END_RCPP
-}
-// Array__offset
-int Array__offset(const std::shared_ptr<arrow::Array>& x);
-RcppExport SEXP _arrow_Array__offset(SEXP xSEXP) {
-BEGIN_RCPP
-    Rcpp::RObject rcpp_result_gen;
-    Rcpp::RNGScope rcpp_rngScope_gen;
-    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type x(xSEXP);
-    rcpp_result_gen = Rcpp::wrap(Array__offset(x));
-    return rcpp_result_gen;
-END_RCPP
-}
-// Array__null_count
-int Array__null_count(const std::shared_ptr<arrow::Array>& x);
-RcppExport SEXP _arrow_Array__null_count(SEXP xSEXP) {
-BEGIN_RCPP
-    Rcpp::RObject rcpp_result_gen;
-    Rcpp::RNGScope rcpp_rngScope_gen;
-    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type x(xSEXP);
-    rcpp_result_gen = Rcpp::wrap(Array__null_count(x));
-    return rcpp_result_gen;
-END_RCPP
-}
-// Array__type
-std::shared_ptr<arrow::DataType> Array__type(const 
std::shared_ptr<arrow::Array>& x);
-RcppExport SEXP _arrow_Array__type(SEXP xSEXP) {
-BEGIN_RCPP
-    Rcpp::RObject rcpp_result_gen;
-    Rcpp::RNGScope rcpp_rngScope_gen;
-    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type x(xSEXP);
-    rcpp_result_gen = Rcpp::wrap(Array__type(x));
-    return rcpp_result_gen;
-END_RCPP
-}
-// Array__ToString
-std::string Array__ToString(const std::shared_ptr<arrow::Array>& x);
-RcppExport SEXP _arrow_Array__ToString(SEXP xSEXP) {
-BEGIN_RCPP
-    Rcpp::RObject rcpp_result_gen;
-    Rcpp::RNGScope rcpp_rngScope_gen;
-    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type x(xSEXP);
-    rcpp_result_gen = Rcpp::wrap(Array__ToString(x));
-    return rcpp_result_gen;
-END_RCPP
-}
-// Array__type_id
-arrow::Type::type Array__type_id(const std::shared_ptr<arrow::Array>& x);
-RcppExport SEXP _arrow_Array__type_id(SEXP xSEXP) {
-BEGIN_RCPP
-    Rcpp::RObject rcpp_result_gen;
-    Rcpp::RNGScope rcpp_rngScope_gen;
-    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type x(xSEXP);
-    rcpp_result_gen = Rcpp::wrap(Array__type_id(x));
-    return rcpp_result_gen;
-END_RCPP
-}
-// Array__Equals
-bool Array__Equals(const std::shared_ptr<arrow::Array>& lhs, const 
std::shared_ptr<arrow::Array>& rhs);
-RcppExport SEXP _arrow_Array__Equals(SEXP lhsSEXP, SEXP rhsSEXP) {
-BEGIN_RCPP
-    Rcpp::RObject rcpp_result_gen;
-    Rcpp::RNGScope rcpp_rngScope_gen;
-    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type lhs(lhsSEXP);
-    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type rhs(rhsSEXP);
-    rcpp_result_gen = Rcpp::wrap(Array__Equals(lhs, rhs));
-    return rcpp_result_gen;
-END_RCPP
-}
-// Array__ApproxEquals
-bool Array__ApproxEquals(const std::shared_ptr<arrow::Array>& lhs, const 
std::shared_ptr<arrow::Array>& rhs);
-RcppExport SEXP _arrow_Array__ApproxEquals(SEXP lhsSEXP, SEXP rhsSEXP) {
-BEGIN_RCPP
-    Rcpp::RObject rcpp_result_gen;
-    Rcpp::RNGScope rcpp_rngScope_gen;
-    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type lhs(lhsSEXP);
-    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type rhs(rhsSEXP);
-    rcpp_result_gen = Rcpp::wrap(Array__ApproxEquals(lhs, rhs));
-    return rcpp_result_gen;
-END_RCPP
-}
-// Array__data
-std::shared_ptr<arrow::ArrayData> Array__data(const 
std::shared_ptr<arrow::Array>& array);
-RcppExport SEXP _arrow_Array__data(SEXP arraySEXP) {
-BEGIN_RCPP
-    Rcpp::RObject rcpp_result_gen;
-    Rcpp::RNGScope rcpp_rngScope_gen;
-    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type array(arraySEXP);
-    rcpp_result_gen = Rcpp::wrap(Array__data(array));
-    return rcpp_result_gen;
-END_RCPP
-}
-// Array__RangeEquals
-bool Array__RangeEquals(const std::shared_ptr<arrow::Array>& self, const 
std::shared_ptr<arrow::Array>& other, int start_idx, int end_idx, int 
other_start_idx);
-RcppExport SEXP _arrow_Array__RangeEquals(SEXP selfSEXP, SEXP otherSEXP, SEXP 
start_idxSEXP, SEXP end_idxSEXP, SEXP other_start_idxSEXP) {
-BEGIN_RCPP
-    Rcpp::RObject rcpp_result_gen;
-    Rcpp::RNGScope rcpp_rngScope_gen;
-    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type self(selfSEXP);
-    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type other(otherSEXP);
-    Rcpp::traits::input_parameter< int >::type start_idx(start_idxSEXP);
-    Rcpp::traits::input_parameter< int >::type end_idx(end_idxSEXP);
-    Rcpp::traits::input_parameter< int >::type 
other_start_idx(other_start_idxSEXP);
-    rcpp_result_gen = Rcpp::wrap(Array__RangeEquals(self, other, start_idx, 
end_idx, other_start_idx));
-    return rcpp_result_gen;
-END_RCPP
-}
-// Array__Mask
-LogicalVector Array__Mask(const std::shared_ptr<arrow::Array>& array);
-RcppExport SEXP _arrow_Array__Mask(SEXP arraySEXP) {
-BEGIN_RCPP
-    Rcpp::RObject rcpp_result_gen;
-    Rcpp::RNGScope rcpp_rngScope_gen;
-    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& 
>::type array(arraySEXP);
-    rcpp_result_gen = Rcpp::wrap(Array__Mask(array));
-    return rcpp_result_gen;
-END_RCPP
-}
-// DictionaryArray__indices
-std::shared_ptr<arrow::Array> DictionaryArray__indices(const 
std::shared_ptr<arrow::DictionaryArray>& array);
-RcppExport SEXP _arrow_DictionaryArray__indices(SEXP arraySEXP) {
-BEGIN_RCPP
-    Rcpp::RObject rcpp_result_gen;
-    Rcpp::RNGScope rcpp_rngScope_gen;
-    Rcpp::traits::input_parameter< const 
std::shared_ptr<arrow::DictionaryArray>& >::type array(arraySEXP);
-    rcpp_result_gen = Rcpp::wrap(DictionaryArray__indices(array));
-    return rcpp_result_gen;
-END_RCPP
-}
-// DictionaryArray__dictionary
-std::shared_ptr<arrow::Array> DictionaryArray__dictionary(const 
std::shared_ptr<arrow::DictionaryArray>& array);
-RcppExport SEXP _arrow_DictionaryArray__dictionary(SEXP arraySEXP) {
-BEGIN_RCPP
-    Rcpp::RObject rcpp_result_gen;
-    Rcpp::RNGScope rcpp_rngScope_gen;
-    Rcpp::traits::input_parameter< const 
std::shared_ptr<arrow::DictionaryArray>& >::type array(arraySEXP);
-    rcpp_result_gen = Rcpp::wrap(DictionaryArray__dictionary(array));
-    return rcpp_result_gen;
-END_RCPP
-}
-// Field__initialize
-std::shared_ptr<arrow::Field> Field__initialize(const std::string& name, const 
std::shared_ptr<arrow::DataType>& type, bool nullable);
-RcppExport SEXP _arrow_Field__initialize(SEXP nameSEXP, SEXP typeSEXP, SEXP 
nullableSEXP) {
-BEGIN_RCPP
-    Rcpp::RObject rcpp_result_gen;
-    Rcpp::RNGScope rcpp_rngScope_gen;
-    Rcpp::traits::input_parameter< const std::string& >::type name(nameSEXP);
-    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::DataType>& 
>::type type(typeSEXP);
-    Rcpp::traits::input_parameter< bool >::type nullable(nullableSEXP);
-    rcpp_result_gen = Rcpp::wrap(Field__initialize(name, type, nullable));
-    return rcpp_result_gen;
-END_RCPP
-}
-// Field__ToString
-std::string Field__ToString(const std::shared_ptr<arrow::Field>& type);
-RcppExport SEXP _arrow_Field__ToString(SEXP typeSEXP) {
-BEGIN_RCPP
-    Rcpp::RObject rcpp_result_gen;
-    Rcpp::RNGScope rcpp_rngScope_gen;
-    Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Field>& 
>::type type(typeSEXP);
-    rcpp_result_gen = Rcpp::wrap(Field__ToString(type));
-    return rcpp_result_gen;
-END_RCPP
-}
-// Field__name
-std::string Field__name(std::shared_ptr<arrow::Field> type);
-RcppExport SEXP _arrow_Field__name(SEXP typeSEXP) {
-BEGIN_RCPP
-    Rcpp::RObject rcpp_result_gen;
-    Rcpp::RNGScope rcpp_rngScope_gen;
-    Rcpp::traits::input_parameter< std::shared_ptr<arrow::Field> >::type 
type(typeSEXP);
-    rcpp_result_gen = Rcpp::wrap(Field__name(type));
-    return rcpp_result_gen;
-END_RCPP
-}
-// Field__nullable
-bool Field__nullable(std::shared_ptr<arrow::Field> type);
-RcppExport SEXP _arrow_Field__nullable(SEXP typeSEXP) {
-BEGIN_RCPP
-    Rcpp::RObject rcpp_result_gen;
-    Rcpp::RNGScope rcpp_rngScope_gen;
-    Rcpp::traits::input_parameter< std::shared_ptr<arrow::Field> >::type 
type(typeSEXP);
-    rcpp_result_gen = Rcpp::wrap(Field__nullable(type));
+    rcpp_result_gen = Rcpp::wrap(Table__column(table, i));
     return rcpp_result_gen;
 END_RCPP
 }
 
 static const R_CallMethodDef CallEntries[] = {
+    {"_arrow_Array__from_vector", (DL_FUNC) &_arrow_Array__from_vector, 1},
+    {"_arrow_Array__as_vector", (DL_FUNC) &_arrow_Array__as_vector, 1},
+    {"_arrow_Array__Slice1", (DL_FUNC) &_arrow_Array__Slice1, 2},
+    {"_arrow_Array__Slice2", (DL_FUNC) &_arrow_Array__Slice2, 3},
+    {"_arrow_Array__IsNull", (DL_FUNC) &_arrow_Array__IsNull, 2},
+    {"_arrow_Array__IsValid", (DL_FUNC) &_arrow_Array__IsValid, 2},
+    {"_arrow_Array__length", (DL_FUNC) &_arrow_Array__length, 1},
+    {"_arrow_Array__offset", (DL_FUNC) &_arrow_Array__offset, 1},
+    {"_arrow_Array__null_count", (DL_FUNC) &_arrow_Array__null_count, 1},
+    {"_arrow_Array__type", (DL_FUNC) &_arrow_Array__type, 1},
+    {"_arrow_Array__ToString", (DL_FUNC) &_arrow_Array__ToString, 1},
+    {"_arrow_Array__type_id", (DL_FUNC) &_arrow_Array__type_id, 1},
+    {"_arrow_Array__Equals", (DL_FUNC) &_arrow_Array__Equals, 2},
+    {"_arrow_Array__ApproxEquals", (DL_FUNC) &_arrow_Array__ApproxEquals, 2},
+    {"_arrow_Array__data", (DL_FUNC) &_arrow_Array__data, 1},
+    {"_arrow_Array__RangeEquals", (DL_FUNC) &_arrow_Array__RangeEquals, 5},
+    {"_arrow_Array__Mask", (DL_FUNC) &_arrow_Array__Mask, 1},
+    {"_arrow_DictionaryArray__indices", (DL_FUNC) 
&_arrow_DictionaryArray__indices, 1},
+    {"_arrow_DictionaryArray__dictionary", (DL_FUNC) 
&_arrow_DictionaryArray__dictionary, 1},
     {"_arrow_ArrayData__get_type", (DL_FUNC) &_arrow_ArrayData__get_type, 1},
     {"_arrow_ArrayData__get_length", (DL_FUNC) &_arrow_ArrayData__get_length, 
1},
     {"_arrow_ArrayData__get_null_count", (DL_FUNC) 
&_arrow_ArrayData__get_null_count, 1},
     {"_arrow_ArrayData__get_offset", (DL_FUNC) &_arrow_ArrayData__get_offset, 
1},
+    {"_arrow_Buffer__is_mutable", (DL_FUNC) &_arrow_Buffer__is_mutable, 1},
+    {"_arrow_Buffer__ZeroPadding", (DL_FUNC) &_arrow_Buffer__ZeroPadding, 1},
+    {"_arrow_Buffer__capacity", (DL_FUNC) &_arrow_Buffer__capacity, 1},
+    {"_arrow_Buffer__size", (DL_FUNC) &_arrow_Buffer__size, 1},
+    {"_arrow_r___RBuffer__initialize", (DL_FUNC) 
&_arrow_r___RBuffer__initialize, 1},
     {"_arrow_ChunkedArray__length", (DL_FUNC) &_arrow_ChunkedArray__length, 1},
     {"_arrow_ChunkedArray__null_count", (DL_FUNC) 
&_arrow_ChunkedArray__null_count, 1},
     {"_arrow_ChunkedArray__num_chunks", (DL_FUNC) 
&_arrow_ChunkedArray__num_chunks, 1},
@@ -1330,6 +1564,21 @@ static const R_CallMethodDef CallEntries[] = {
     {"_arrow_DictionaryType__name", (DL_FUNC) &_arrow_DictionaryType__name, 1},
     {"_arrow_DictionaryType__dictionary", (DL_FUNC) 
&_arrow_DictionaryType__dictionary, 1},
     {"_arrow_DictionaryType__ordered", (DL_FUNC) 
&_arrow_DictionaryType__ordered, 1},
+    {"_arrow_Field__initialize", (DL_FUNC) &_arrow_Field__initialize, 3},
+    {"_arrow_Field__ToString", (DL_FUNC) &_arrow_Field__ToString, 1},
+    {"_arrow_Field__name", (DL_FUNC) &_arrow_Field__name, 1},
+    {"_arrow_Field__nullable", (DL_FUNC) &_arrow_Field__nullable, 1},
+    {"_arrow_io___Readable__Read", (DL_FUNC) &_arrow_io___Readable__Read, 2},
+    {"_arrow_io___InputStream__Close", (DL_FUNC) 
&_arrow_io___InputStream__Close, 1},
+    {"_arrow_io___RandomAccessFile__GetSize", (DL_FUNC) 
&_arrow_io___RandomAccessFile__GetSize, 1},
+    {"_arrow_io___RandomAccessFile__supports_zero_copy", (DL_FUNC) 
&_arrow_io___RandomAccessFile__supports_zero_copy, 1},
+    {"_arrow_io___RandomAccessFile__Seek", (DL_FUNC) 
&_arrow_io___RandomAccessFile__Seek, 2},
+    {"_arrow_io___RandomAccessFile__Tell", (DL_FUNC) 
&_arrow_io___RandomAccessFile__Tell, 1},
+    {"_arrow_io___MemoryMappedFile__Create", (DL_FUNC) 
&_arrow_io___MemoryMappedFile__Create, 2},
+    {"_arrow_io___MemoryMappedFile__Open", (DL_FUNC) 
&_arrow_io___MemoryMappedFile__Open, 2},
+    {"_arrow_io___MemoryMappedFile__Resize", (DL_FUNC) 
&_arrow_io___MemoryMappedFile__Resize, 2},
+    {"_arrow_io___ReadableFile__Open", (DL_FUNC) 
&_arrow_io___ReadableFile__Open, 1},
+    {"_arrow_io___BufferReader__initialize", (DL_FUNC) 
&_arrow_io___BufferReader__initialize, 1},
     {"_arrow_MemoryPool__default", (DL_FUNC) &_arrow_MemoryPool__default, 0},
     {"_arrow_MemoryPool__bytes_allocated", (DL_FUNC) 
&_arrow_MemoryPool__bytes_allocated, 1},
     {"_arrow_MemoryPool__max_memory", (DL_FUNC) 
&_arrow_MemoryPool__max_memory, 1},
@@ -1338,7 +1587,8 @@ static const R_CallMethodDef CallEntries[] = {
     {"_arrow_RecordBatch__schema", (DL_FUNC) &_arrow_RecordBatch__schema, 1},
     {"_arrow_RecordBatch__column", (DL_FUNC) &_arrow_RecordBatch__column, 2},
     {"_arrow_RecordBatch__to_dataframe", (DL_FUNC) 
&_arrow_RecordBatch__to_dataframe, 1},
-    {"_arrow_read_record_batch_", (DL_FUNC) &_arrow_read_record_batch_, 1},
+    {"_arrow_read_record_batch_RandomAccessFile", (DL_FUNC) 
&_arrow_read_record_batch_RandomAccessFile, 1},
+    {"_arrow_read_record_batch_BufferReader", (DL_FUNC) 
&_arrow_read_record_batch_BufferReader, 1},
     {"_arrow_RecordBatch__to_file", (DL_FUNC) &_arrow_RecordBatch__to_file, 2},
     {"_arrow_RecordBatch__to_stream", (DL_FUNC) 
&_arrow_RecordBatch__to_stream, 1},
     {"_arrow_RecordBatch__from_dataframe", (DL_FUNC) 
&_arrow_RecordBatch__from_dataframe, 1},
@@ -1353,32 +1603,11 @@ static const R_CallMethodDef CallEntries[] = {
     {"_arrow_Table__num_rows", (DL_FUNC) &_arrow_Table__num_rows, 1},
     {"_arrow_Table__schema", (DL_FUNC) &_arrow_Table__schema, 1},
     {"_arrow_Table__to_file", (DL_FUNC) &_arrow_Table__to_file, 2},
-    {"_arrow_read_table_", (DL_FUNC) &_arrow_read_table_, 1},
+    {"_arrow_Table__to_stream", (DL_FUNC) &_arrow_Table__to_stream, 1},
+    {"_arrow_read_table_RandomAccessFile", (DL_FUNC) 
&_arrow_read_table_RandomAccessFile, 1},
+    {"_arrow_read_table_BufferReader", (DL_FUNC) 
&_arrow_read_table_BufferReader, 1},
     {"_arrow_Table__to_dataframe", (DL_FUNC) &_arrow_Table__to_dataframe, 1},
     {"_arrow_Table__column", (DL_FUNC) &_arrow_Table__column, 2},
-    {"_arrow_Array__from_vector", (DL_FUNC) &_arrow_Array__from_vector, 1},
-    {"_arrow_Array__as_vector", (DL_FUNC) &_arrow_Array__as_vector, 1},
-    {"_arrow_Array__Slice1", (DL_FUNC) &_arrow_Array__Slice1, 2},
-    {"_arrow_Array__Slice2", (DL_FUNC) &_arrow_Array__Slice2, 3},
-    {"_arrow_Array__IsNull", (DL_FUNC) &_arrow_Array__IsNull, 2},
-    {"_arrow_Array__IsValid", (DL_FUNC) &_arrow_Array__IsValid, 2},
-    {"_arrow_Array__length", (DL_FUNC) &_arrow_Array__length, 1},
-    {"_arrow_Array__offset", (DL_FUNC) &_arrow_Array__offset, 1},
-    {"_arrow_Array__null_count", (DL_FUNC) &_arrow_Array__null_count, 1},
-    {"_arrow_Array__type", (DL_FUNC) &_arrow_Array__type, 1},
-    {"_arrow_Array__ToString", (DL_FUNC) &_arrow_Array__ToString, 1},
-    {"_arrow_Array__type_id", (DL_FUNC) &_arrow_Array__type_id, 1},
-    {"_arrow_Array__Equals", (DL_FUNC) &_arrow_Array__Equals, 2},
-    {"_arrow_Array__ApproxEquals", (DL_FUNC) &_arrow_Array__ApproxEquals, 2},
-    {"_arrow_Array__data", (DL_FUNC) &_arrow_Array__data, 1},
-    {"_arrow_Array__RangeEquals", (DL_FUNC) &_arrow_Array__RangeEquals, 5},
-    {"_arrow_Array__Mask", (DL_FUNC) &_arrow_Array__Mask, 1},
-    {"_arrow_DictionaryArray__indices", (DL_FUNC) 
&_arrow_DictionaryArray__indices, 1},
-    {"_arrow_DictionaryArray__dictionary", (DL_FUNC) 
&_arrow_DictionaryArray__dictionary, 1},
-    {"_arrow_Field__initialize", (DL_FUNC) &_arrow_Field__initialize, 3},
-    {"_arrow_Field__ToString", (DL_FUNC) &_arrow_Field__ToString, 1},
-    {"_arrow_Field__name", (DL_FUNC) &_arrow_Field__name, 1},
-    {"_arrow_Field__nullable", (DL_FUNC) &_arrow_Field__nullable, 1},
     {NULL, NULL, 0}
 };
 
diff --git a/r/src/RecordBatch.cpp b/r/src/RecordBatch.cpp
index ec99c2e..2dd47d2 100644
--- a/r/src/RecordBatch.cpp
+++ b/r/src/RecordBatch.cpp
@@ -63,17 +63,26 @@ List RecordBatch__to_dataframe(const 
std::shared_ptr<arrow::RecordBatch>& batch)
 }
 
 // [[Rcpp::export]]
-std::shared_ptr<arrow::RecordBatch> read_record_batch_(std::string path) {
-  std::shared_ptr<arrow::io::ReadableFile> stream;
+std::shared_ptr<arrow::RecordBatch> read_record_batch_RandomAccessFile(
+    const std::shared_ptr<arrow::io::RandomAccessFile>& stream) {
   std::shared_ptr<arrow::ipc::RecordBatchFileReader> rbf_reader;
-
-  R_ERROR_NOT_OK(arrow::io::ReadableFile::Open(path, &stream));
   R_ERROR_NOT_OK(arrow::ipc::RecordBatchFileReader::Open(stream, &rbf_reader));
 
   std::shared_ptr<arrow::RecordBatch> batch;
   R_ERROR_NOT_OK(rbf_reader->ReadRecordBatch(0, &batch));
 
-  R_ERROR_NOT_OK(stream->Close());
+  return batch;
+}
+
+// [[Rcpp::export]]
+std::shared_ptr<arrow::RecordBatch> read_record_batch_BufferReader(
+    const std::shared_ptr<arrow::io::BufferReader>& stream) {
+  std::shared_ptr<arrow::ipc::RecordBatchReader> rbf_reader;
+  R_ERROR_NOT_OK(arrow::ipc::RecordBatchStreamReader::Open(stream, 
&rbf_reader));
+
+  std::shared_ptr<arrow::RecordBatch> batch;
+  R_ERROR_NOT_OK(rbf_reader->ReadNext(&batch));
+
   return batch;
 }
 
@@ -95,20 +104,20 @@ int RecordBatch__to_file(const 
std::shared_ptr<arrow::RecordBatch>& batch,
   return offset;
 }
 
-// [[Rcpp::export]]
-RawVector RecordBatch__to_stream(const std::shared_ptr<arrow::RecordBatch>& 
batch) {
+int64_t RecordBatch_size(const std::shared_ptr<arrow::RecordBatch>& batch) {
   io::MockOutputStream mock_sink;
   R_ERROR_NOT_OK(arrow::ipc::WriteRecordBatchStream({batch}, &mock_sink));
+  return mock_sink.GetExtentBytesWritten();
+}
 
-  RawVector res(mock_sink.GetExtentBytesWritten());
-
-  std::shared_ptr<arrow::MutableBuffer> raw_buffer;
-  raw_buffer.reset(new arrow::MutableBuffer(res.begin(), res.size()));
-
-  std::unique_ptr<arrow::io::FixedSizeBufferWriter> sink;
-  sink.reset(new arrow::io::FixedSizeBufferWriter(raw_buffer));
+// [[Rcpp::export]]
+RawVector RecordBatch__to_stream(const std::shared_ptr<arrow::RecordBatch>& 
batch) {
+  auto n = RecordBatch_size(batch);
 
-  R_ERROR_NOT_OK(arrow::ipc::WriteRecordBatchStream({batch}, sink.get()));
+  RawVector res(n);
+  auto raw_buffer = std::make_shared<arrow::MutableBuffer>(res.begin(), 
res.size());
+  arrow::io::FixedSizeBufferWriter sink(raw_buffer);
+  R_ERROR_NOT_OK(arrow::ipc::WriteRecordBatchStream({batch}, &sink));
 
   return res;
 }
diff --git a/r/src/Table.cpp b/r/src/Table.cpp
index 52227d5..adc3832 100644
--- a/r/src/Table.cpp
+++ b/r/src/Table.cpp
@@ -63,11 +63,31 @@ int Table__to_file(const std::shared_ptr<arrow::Table>& 
table, std::string path)
 }
 
 // [[Rcpp::export]]
-std::shared_ptr<arrow::Table> read_table_(std::string path) {
-  std::shared_ptr<arrow::io::ReadableFile> stream;
-  std::shared_ptr<arrow::ipc::RecordBatchFileReader> rbf_reader;
+RawVector Table__to_stream(const std::shared_ptr<arrow::Table>& table) {
+  arrow::io::MockOutputStream mock_sink;
+  std::shared_ptr<arrow::ipc::RecordBatchWriter> writer;
+  R_ERROR_NOT_OK(
+      arrow::ipc::RecordBatchStreamWriter::Open(&mock_sink, table->schema(), 
&writer));
+  R_ERROR_NOT_OK(writer->WriteTable(*table));
+  R_ERROR_NOT_OK(writer->Close());
+  auto n = mock_sink.GetExtentBytesWritten();
+
+  RawVector res(no_init(n));
+  auto raw_buffer = std::make_shared<arrow::MutableBuffer>(res.begin(), 
res.size());
+  arrow::io::FixedSizeBufferWriter sink(raw_buffer);
+
+  R_ERROR_NOT_OK(
+      arrow::ipc::RecordBatchStreamWriter::Open(&sink, table->schema(), 
&writer));
+  R_ERROR_NOT_OK(writer->WriteTable(*table));
+  R_ERROR_NOT_OK(writer->Close());
+
+  return res;
+}
 
-  R_ERROR_NOT_OK(arrow::io::ReadableFile::Open(path, &stream));
+// [[Rcpp::export]]
+std::shared_ptr<arrow::Table> read_table_RandomAccessFile(
+    const std::shared_ptr<arrow::io::RandomAccessFile>& stream) {
+  std::shared_ptr<arrow::ipc::RecordBatchFileReader> rbf_reader;
   R_ERROR_NOT_OK(arrow::ipc::RecordBatchFileReader::Open(stream, &rbf_reader));
 
   int num_batches = rbf_reader->num_record_batches();
@@ -78,7 +98,27 @@ std::shared_ptr<arrow::Table> read_table_(std::string path) {
 
   std::shared_ptr<arrow::Table> table;
   R_ERROR_NOT_OK(arrow::Table::FromRecordBatches(std::move(batches), &table));
-  R_ERROR_NOT_OK(stream->Close());
+
+  return table;
+}
+
+// [[Rcpp::export]]
+std::shared_ptr<arrow::Table> read_table_BufferReader(
+    const std::shared_ptr<arrow::io::BufferReader>& stream) {
+  std::shared_ptr<arrow::ipc::RecordBatchReader> rb_reader;
+  R_ERROR_NOT_OK(arrow::ipc::RecordBatchStreamReader::Open(stream, 
&rb_reader));
+  std::shared_ptr<arrow::RecordBatch> batch;
+
+  std::vector<std::shared_ptr<arrow::RecordBatch>> batches;
+  while (true) {
+    R_ERROR_NOT_OK(rb_reader->ReadNext(&batch));
+    if (!batch) break;
+    batches.push_back(batch);
+  }
+
+  std::shared_ptr<arrow::Table> table;
+  R_ERROR_NOT_OK(arrow::Table::FromRecordBatches(std::move(batches), &table));
+
   return table;
 }
 
diff --git a/r/src/array.cpp b/r/src/array.cpp
index 0f6c18a..4f9eb6c 100644
--- a/r/src/array.cpp
+++ b/r/src/array.cpp
@@ -23,27 +23,12 @@ using namespace arrow;
 namespace arrow {
 namespace r {
 
-template <int RTYPE, typename Vec = Rcpp::Vector<RTYPE>>
-class SimpleRBuffer : public Buffer {
- public:
-  SimpleRBuffer(Vec vec)
-      : Buffer(reinterpret_cast<const uint8_t*>(vec.begin()),
-               vec.size() * sizeof(typename Vec::stored_type)),
-        vec_(vec) {}
-
- private:
-  // vec_ holds the memory
-  Vec vec_;
-};
-
-// ---------------------------- R vector -> Array
-
 template <int RTYPE, typename Type>
 std::shared_ptr<Array> SimpleArray(SEXP x) {
   Rcpp::Vector<RTYPE> vec(x);
   auto n = vec.size();
-  std::vector<std::shared_ptr<Buffer>> buffers{
-      nullptr, std::make_shared<SimpleRBuffer<RTYPE>>(vec)};
+  std::vector<std::shared_ptr<Buffer>> buffers{nullptr,
+                                               
std::make_shared<RBuffer<RTYPE>>(vec)};
 
   int null_count = 0;
   if (RTYPE != RAWSXP) {
diff --git a/r/src/arrow_types.h b/r/src/arrow_types.h
index 879f59a..43ee41d 100644
--- a/r/src/arrow_types.h
+++ b/r/src/arrow_types.h
@@ -21,6 +21,8 @@
 
 #undef Free
 #include <arrow/api.h>
+#include <arrow/io/file.h>
+#include <arrow/io/memory.h>
 #include <arrow/type.h>
 
 #define R_ERROR_NOT_OK(s)                  \
@@ -62,6 +64,7 @@ RCPP_EXPOSED_ENUM_NODECL(arrow::Type::type)
 RCPP_EXPOSED_ENUM_NODECL(arrow::DateUnit)
 RCPP_EXPOSED_ENUM_NODECL(arrow::TimeUnit::type)
 RCPP_EXPOSED_ENUM_NODECL(arrow::StatusCode)
+RCPP_EXPOSED_ENUM_NODECL(arrow::io::FileMode::type)
 
 namespace Rcpp {
 namespace traits {
@@ -131,5 +134,18 @@ inline const T* GetValuesSafely(const 
std::shared_ptr<ArrayData>& data, int i,
   return reinterpret_cast<const T*>(buffer->data()) + offset;
 }
 
+template <int RTYPE, typename Vec = Rcpp::Vector<RTYPE>>
+class RBuffer : public Buffer {
+ public:
+  RBuffer(Vec vec)
+      : Buffer(reinterpret_cast<const uint8_t*>(vec.begin()),
+               vec.size() * sizeof(typename Vec::stored_type)),
+        vec_(vec) {}
+
+ private:
+  // vec_ holds the memory
+  Vec vec_;
+};
+
 }  // namespace r
 }  // namespace arrow
diff --git a/r/src/buffer.cpp b/r/src/buffer.cpp
new file mode 100644
index 0000000..8f4ca8e
--- /dev/null
+++ b/r/src/buffer.cpp
@@ -0,0 +1,54 @@
+// 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.
+
+#include "arrow_types.h"
+
+// [[Rcpp::export]]
+bool Buffer__is_mutable(const std::shared_ptr<arrow::Buffer>& buffer) {
+  return buffer->is_mutable();
+}
+
+// [[Rcpp::export]]
+void Buffer__ZeroPadding(const std::shared_ptr<arrow::Buffer>& buffer) {
+  buffer->ZeroPadding();
+}
+
+// [[Rcpp::export]]
+int64_t Buffer__capacity(const std::shared_ptr<arrow::Buffer>& buffer) {
+  return buffer->capacity();
+}
+
+// [[Rcpp::export]]
+int64_t Buffer__size(const std::shared_ptr<arrow::Buffer>& buffer) {
+  return buffer->size();
+}
+
+// [[Rcpp::export]]
+std::shared_ptr<arrow::Buffer> r___RBuffer__initialize(SEXP x) {
+  switch (TYPEOF(x)) {
+    case RAWSXP:
+      return std::make_shared<arrow::r::RBuffer<RAWSXP>>(x);
+    case REALSXP:
+      return std::make_shared<arrow::r::RBuffer<REALSXP>>(x);
+    case INTSXP:
+      return std::make_shared<arrow::r::RBuffer<INTSXP>>(x);
+    default:
+      Rcpp::stop(
+          tfm::format("R object of type %s not supported", 
Rf_type2char(TYPEOF(x))));
+  }
+  return nullptr;
+}
diff --git a/r/src/io.cpp b/r/src/io.cpp
new file mode 100644
index 0000000..e528720
--- /dev/null
+++ b/r/src/io.cpp
@@ -0,0 +1,109 @@
+// 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.
+
+#include "arrow_types.h"
+
+using namespace Rcpp;
+
+// ------ arrow::io::Readable
+
+// [[Rcpp::export]]
+std::shared_ptr<arrow::Buffer> io___Readable__Read(
+    const std::shared_ptr<arrow::io::Readable>& x, int64_t nbytes) {
+  std::shared_ptr<arrow::Buffer> buf;
+  R_ERROR_NOT_OK(x->Read(nbytes, &buf));
+  return buf;
+}
+
+// ------ arrow::io::InputStream
+
+// [[Rcpp::export]]
+void io___InputStream__Close(const std::shared_ptr<arrow::io::InputStream>& x) 
{
+  R_ERROR_NOT_OK(x->Close());
+}
+
+// ------ arrow::io::RandomAccessFile
+
+// [[Rcpp::export]]
+int64_t io___RandomAccessFile__GetSize(
+    const std::shared_ptr<arrow::io::RandomAccessFile>& x) {
+  int64_t out;
+  R_ERROR_NOT_OK(x->GetSize(&out));
+  return out;
+}
+
+// [[Rcpp::export]]
+bool io___RandomAccessFile__supports_zero_copy(
+    const std::shared_ptr<arrow::io::RandomAccessFile>& x) {
+  return x->supports_zero_copy();
+}
+
+// [[Rcpp::export]]
+void io___RandomAccessFile__Seek(const 
std::shared_ptr<arrow::io::RandomAccessFile>& x,
+                                 int64_t position) {
+  R_ERROR_NOT_OK(x->Seek(position));
+}
+
+// [[Rcpp::export]]
+int64_t io___RandomAccessFile__Tell(
+    const std::shared_ptr<arrow::io::RandomAccessFile>& x) {
+  int64_t out;
+  R_ERROR_NOT_OK(x->Tell(&out));
+  return out;
+}
+
+// ------ arrow::io::MemoryMappedFile
+
+// [[Rcpp::export]]
+std::shared_ptr<arrow::io::MemoryMappedFile> io___MemoryMappedFile__Create(
+    const std::string& path, int64_t size) {
+  std::shared_ptr<arrow::io::MemoryMappedFile> out;
+  R_ERROR_NOT_OK(arrow::io::MemoryMappedFile::Create(path, size, &out));
+  return out;
+}
+
+// [[Rcpp::export]]
+std::shared_ptr<arrow::io::MemoryMappedFile> io___MemoryMappedFile__Open(
+    const std::string& path, arrow::io::FileMode::type mode) {
+  std::shared_ptr<arrow::io::MemoryMappedFile> out;
+  R_ERROR_NOT_OK(arrow::io::MemoryMappedFile::Open(path, mode, &out));
+  return out;
+}
+
+// [[Rcpp::export]]
+void io___MemoryMappedFile__Resize(const 
std::shared_ptr<arrow::io::MemoryMappedFile>& x,
+                                   int64_t size) {
+  R_ERROR_NOT_OK(x->Resize(size));
+}
+
+// ------ arrow::io::ReadableFile
+
+// [[Rcpp::export]]
+std::shared_ptr<arrow::io::ReadableFile> io___ReadableFile__Open(
+    const std::string& path) {
+  std::shared_ptr<arrow::io::ReadableFile> out;
+  R_ERROR_NOT_OK(arrow::io::ReadableFile::Open(path, &out));
+  return out;
+}
+
+// ------ arrow::io::BufferReader
+
+// [[Rcpp::export]]
+std::shared_ptr<arrow::io::BufferReader> io___BufferReader__initialize(
+    const std::shared_ptr<arrow::Buffer>& buffer) {
+  return std::make_shared<arrow::io::BufferReader>(buffer);
+}
diff --git a/r/tests/testthat/test-RecordBatch.R 
b/r/tests/testthat/test-RecordBatch.R
index 454404f..0d9d0d9 100644
--- a/r/tests/testthat/test-RecordBatch.R
+++ b/r/tests/testthat/test-RecordBatch.R
@@ -121,9 +121,40 @@ test_that("RecordBatch can output stream", {
     lgl = sample(c(TRUE, FALSE, NA), 10, replace = TRUE),
     chr = letters[1:10]
   )
-
   record <- record_batch(tbl)
   stream <- record$to_stream()
 
   expect_gt(length(stream), 0)
 })
+
+test_that("read_record_batch handles ReadableFile and MemoryMappedFile 
(ARROW-3450)", {
+  tbl <- tibble::tibble(
+    int = 1:10, dbl = as.numeric(1:10),
+    lgl = sample(c(TRUE, FALSE, NA), 10, replace = TRUE),
+    chr = letters[1:10]
+  )
+  batch <- record_batch(tbl)
+  tf <- tempfile(); on.exit(unlink(tf))
+  batch$to_file(tf)
+
+  bytes <- batch$to_stream()
+  buf_reader <- buffer_reader(bytes)
+
+  batch1 <- read_record_batch(tf)
+  batch2 <- read_record_batch(fs::path_abs(tf))
+
+  readable_file <- file_open(tf); on.exit(readable_file$Close())
+  batch3 <- read_record_batch(readable_file)
+
+  mmap_file <- mmap_open(tf); on.exit(mmap_file$Close())
+  batch4 <- read_record_batch(mmap_file)
+
+  batch5 <- read_record_batch(bytes)
+  batch6 <- read_record_batch(buf_reader)
+
+  expect_equal(batch, batch1)
+  expect_equal(batch, batch2)
+  expect_equal(batch, batch3)
+  expect_equal(batch, batch4)
+  expect_equal(batch, batch5)
+})
diff --git a/r/tests/testthat/test-Table.R b/r/tests/testthat/test-Table.R
new file mode 100644
index 0000000..e6b2cad
--- /dev/null
+++ b/r/tests/testthat/test-Table.R
@@ -0,0 +1,51 @@
+# 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.
+
+context("arrow::Table")
+
+test_that("read_table handles various input streams (ARROW-3450)", {
+  tbl <- tibble::tibble(
+    int = 1:10, dbl = as.numeric(1:10),
+    lgl = sample(c(TRUE, FALSE, NA), 10, replace = TRUE),
+    chr = letters[1:10]
+  )
+  tab <- arrow::table(tbl)
+  tf <- tempfile(); on.exit(unlink(tf))
+  tab$to_file(tf)
+
+  bytes <- tab$to_stream()
+  buf_reader <- buffer_reader(bytes)
+
+  tab1 <- read_table(tf)
+  tab2 <- read_table(fs::path_abs(tf))
+
+  readable_file <- file_open(tf); on.exit(readable_file$Close())
+  tab3 <- read_table(readable_file)
+
+  mmap_file <- mmap_open(tf); on.exit(mmap_file$Close())
+  tab4 <- read_table(mmap_file)
+
+  tab5 <- read_table(bytes)
+  tab6 <- read_table(buf_reader)
+
+  expect_equal(tab, tab1)
+  expect_equal(tab, tab2)
+  expect_equal(tab, tab3)
+  expect_equal(tab, tab4)
+  expect_equal(tab, tab5)
+  expect_equal(tab, tab6)
+})
diff --git a/r/tests/testthat/test-buffer.R b/r/tests/testthat/test-buffer.R
new file mode 100644
index 0000000..1c0336e
--- /dev/null
+++ b/r/tests/testthat/test-buffer.R
@@ -0,0 +1,39 @@
+# 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.
+
+context("test-buffer")
+
+test_that("arrow::Buffer can be created from raw vector", {
+  vec <- raw(123)
+  buf <- buffer(vec)
+  expect_is(buf, "arrow::Buffer")
+  expect_equal(buf$size(), 123)
+})
+
+test_that("arrow::Buffer can be created from integer vector", {
+  vec <- integer(17)
+  buf <- buffer(vec)
+  expect_is(buf, "arrow::Buffer")
+  expect_equal(buf$size(), 17 * 4)
+})
+
+test_that("arrow::Buffer can be created from numeric vector", {
+  vec <- numeric(17)
+  buf <- buffer(vec)
+  expect_is(buf, "arrow::Buffer")
+  expect_equal(buf$size(), 17 * 8)
+})
diff --git a/r/tests/testthat/test-bufferreader.R 
b/r/tests/testthat/test-bufferreader.R
new file mode 100644
index 0000000..a78153c
--- /dev/null
+++ b/r/tests/testthat/test-bufferreader.R
@@ -0,0 +1,40 @@
+# 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.
+
+context("test-bufferreader")
+
+test_that("BufferReader can be created from R objects", {
+  num <- buffer_reader(numeric(13))
+  int <- buffer_reader(integer(13))
+  raw <- buffer_reader(raw(16))
+
+  expect_is(num, "arrow::io::BufferReader")
+  expect_is(int, "arrow::io::BufferReader")
+  expect_is(raw, "arrow::io::BufferReader")
+
+  expect_equal(num$GetSize(), 13*8)
+  expect_equal(int$GetSize(), 13*4)
+  expect_equal(raw$GetSize(), 16)
+})
+
+test_that("BufferReader can be created from Buffer", {
+  buf <- buffer(raw(76))
+  reader <- buffer_reader(buf)
+
+  expect_is(reader, "arrow::io::BufferReader")
+  expect_equal(reader$GetSize(), 76)
+})

Reply via email to