wjones127 commented on a change in pull request #12751:
URL: https://github.com/apache/arrow/pull/12751#discussion_r839942127



##########
File path: r/R/table.R
##########
@@ -149,6 +149,64 @@ Table$create <- function(..., schema = NULL) {
 #' @export
 names.Table <- function(x) x$ColumnNames()
 
+#' @export
+rbind.Table <- function(...) {
+  tables <- list(...)
+
+  # assert they have same schema
+  schema <- tables[[1]]$schema
+  unequal_schema_idx <- which.min(lapply(tables, function(x) x$schema == 
schema))
+  if (unequal_schema_idx != 1) {
+    stop(paste0(
+      sprintf("Schema at index %i does not match the first schema\n", 
unequal_schema_idx),
+      "Schema 1:\n",
+      tables[[1]]$schema$ToString(),
+      sprintf("\nSchema %i:\n", unequal_schema_idx),
+      tables[[unequal_schema_idx]]$schema$ToString()
+    ))
+  }
+
+  # create chunked array from each column
+  columns <- vector(mode = "list", length = tables[[1]]$num_columns)
+  for (i in seq_len(length(columns))) {
+    columns[[i]] <- do.call(c, lapply(tables, function(tab) tab[[i]]))
+  }
+
+  # return new table
+  args <- columns
+  names(args) <- names(schema)
+  args$schema <- schema
+  do.call(Table$create, args)
+}
+
+#' @export
+cbind.Table <- function(...) {
+  tables <- list(...)
+
+  # Assert they have the same length
+  unequal_length_idx <- which.min(lapply(tables, function(x) x$num_rows == 
tables[[1]]$num_rows))

Review comment:
       Tried it, and TBH I think I prefer the error as is. The vctrs error just 
lacks helpful context:
   
   ```
   Error in `stop_vctrs(message, class = c(class, "vctrs_error_incompatible"), 
       x = x, y = y, details = details, ...)`: Can't recycle `..1` (size 10) to 
match `..2` (size 2).
   ```




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