nealrichardson commented on code in PR #12817:
URL: https://github.com/apache/arrow/pull/12817#discussion_r852397531


##########
r/R/record-batch-reader.R:
##########
@@ -176,3 +176,37 @@ RecordBatchFileReader$create <- function(file) {
   assert_is(file, "InputStream")
   ipc___RecordBatchFileReader__Open(file)
 }
+
+#' Convert an object to an Arrow RecordBatchReader
+#'
+#' @param x An object to convert to a [RecordBatchReader]
+#' @param ... Passed to S3 methods
+#'
+#' @return A [RecordBatchReader]
+#' @export
+#'
+#' @examplesIf arrow_available() && arrow_with_dataset()
+#' reader <- as_record_batch_reader(data.frame(col1 = 1, col2 = "two"))
+#' reader$read_next_batch()
+#'
+as_record_batch_reader <- function(x, ...) {
+  UseMethod("as_record_batch_reader")
+}
+
+#' @rdname as_record_batch_reader
+#' @export
+as_record_batch_reader.RecordBatchReader <- function(x, ...) {
+  x
+}
+
+#' @rdname as_arrow_table
+#' @export
+as_record_batch_reader.default <- function(x, ...) {
+  Scanner$create(x)$ToRecordBatchReader()

Review Comment:
   It's probably more work than it's worth for this PR so you may want to make 
a followup.
   
   * Table has a method in C++ that turns it into a RBR but I don't think we 
have bindings for it.
   * RecordBatch probably does too or it would be trivial to write in r/src; in 
test-record-batch-reader.R there are some tests that make a 
RecordBatchStreamReader via RecordBatchStreamWriter but that seems a little 
baroque
   * data.frame should go through RecordBatch or Table's method
   * Dataset and arrow_dplyr_query should go through the ExecPlan, but there is 
still this issue where the plan is returning a Table due to things that the 
ExecPlan can't evaluate faithfully in C++. That could be improved to return RBR 
in most cases, and for the ones that needed to be Table can be wrapped back in 
RBR. But again that's probably more than you want to bite off here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to