wjones127 commented on code in PR #12751:
URL: https://github.com/apache/arrow/pull/12751#discussion_r847639931


##########
r/R/record-batch.R:
##########
@@ -189,3 +189,52 @@ record_batch <- RecordBatch$create
 
 #' @export
 names.RecordBatch <- function(x) x$names()
+
+#' @export
+rbind.RecordBatch <- function(...) {
+  abort("Use Table$create to combine record batches")
+}
+
+cbind_check_length <- function(target_length, length, idx) {
+  if (length != target_length) {
+    abort(
+      sprintf(
+        "Non-scalar inputs must have an equal number of rows. ..1 has %i, ..%i 
has %i",
+        target_length,
+        idx,
+        length
+      )
+    )
+  }
+}
+
+#' @export
+cbind.RecordBatch <- function(...) {
+  inputs <- list(...)
+  num_rows <- inputs[[1]]$num_rows
+
+  batches <- imap(inputs, function(input, idx) {
+    if (inherits(input, "RecordBatch")) {
+      cbind_check_length(num_rows, input$num_rows, idx)
+      input
+    } else if (is.atomic(input) && length(input) == 1) {
+      RecordBatch$create("{idx}" := rep(input, num_rows))
+    } else {
+      tryCatch(
+        {
+          cbind_check_length(num_rows, length(input), idx)
+          RecordBatch$create("{idx}" := input)
+        },
+        error = function(err) {
+          abort(sprintf("Input ..%i cannot be converted to an Arrow Array: 
%s", idx, err))
+        }
+      )
+    }

Review Comment:
   I got it to work on R >= 4.0. As I suspected, R 3.6 will hijack and calls to 
cbind that have a data.frame as an argument. I don't think there's anything we 
can do to prevent that. If users want to work around that, they could call 
`cbind.RecordBatch` directly and that will work even in old R versions.



-- 
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