wjones127 commented on a change in pull request #12751:
URL: https://github.com/apache/arrow/pull/12751#discussion_r839930496
##########
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:
🤦 Ah right.
And this allocation thing is because `vec_size_common` wants to convert into
data frames, right?
--
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]