paleolimbot commented on code in PR #12751:
URL: https://github.com/apache/arrow/pull/12751#discussion_r848715079
##########
r/R/table.R:
##########
@@ -149,6 +149,75 @@ 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) {
+ abort(c(
+ sprintf("Schema at index %i does not match the first schema",
unequal_schema_idx),
+ i = paste0("Schema 1:\n", schema$ToString()),
+ i = paste0(sprintf("Schema %d:\n", unequal_schema_idx),
+ tables[[unequal_schema_idx]]$schema$ToString())
+ ))
+ }
+
+ # create chunked array for each column
+ columns <- map(seq_len(tables[[1]]$num_columns), function(i) {
+ do.call(c, map(tables, ~ .[[i]]))
+ })
+
+ Table$create(!!!set_names(columns, names(schema)), schema = schema)
+}
+
+#' @export
+cbind.Table <- function(..., call = caller_env()) {
Review Comment:
Just inside the function is what I had in mind.
Are you sure about `caller_env()` though? I really think that `sys.call()`
is what you're after.
``` r
some_fun <- function() {
user_call <- sys.call()
tryCatch(
stop("whoa!"),
error = function(e) {
rlang::abort("whoa revamped!", call = user_call, parent = e)
}
)
}
some_fun()
#> Error in `some_fun()`:
#> ! whoa revamped!
#> Caused by error in `doTryCatch()`:
#> ! whoa!
some_fun2 <- function() {
user_call <- rlang::caller_env()
tryCatch(
stop("whoa!"),
error = function(e) {
rlang::abort("whoa revamped!", call = user_call, parent = e)
}
)
}
some_fun2()
#> Error:
#> ! whoa revamped!
#> Caused by error in `doTryCatch()`:
#> ! whoa!
```
<sup>Created on 2022-04-12 by the [reprex
package](https://reprex.tidyverse.org) (v2.0.1)</sup>
--
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]