jonkeane commented on a change in pull request #12324:
URL: https://github.com/apache/arrow/pull/12324#discussion_r806871651
##########
File path: r/R/array.R
##########
@@ -216,6 +216,76 @@ Array$create <- function(x, type = NULL) {
#' @include arrowExports.R
Array$import_from_c <- ImportArray
+
+#' Concatenate zero or more Arrays
+#'
+#' @param ... zero or more [Array] objects to concatenate
+#' @param type An optional `type` describing the desired
+#' type for the final Array.
+#'
+#' @return An [Array]
+#' @export
+#'
+#' @examples
+#' concat_arrays(Array$create(1:3), Array$create(4:5))
+#'
+concat_arrays <- function(..., type = NULL) {
+ dots <- lapply(list2(...), Array$create, type = type)
+
+ if (length(dots) == 0 && is.null(type)) {
+ return(Array$create(logical(), type = null()))
+ } else if (length(dots) == 0) {
+ return(Array$create(logical(), type = null())$cast(type))
+ }
+
+ if (!is.null(type)) {
+ dots <- lapply(dots, function(array) array$cast(type))
+ }
+
+ arrow__Concatenate(dots)
+}
+
+# The c() method uses non-standard dispatch in R
+# and has some peculiarities when multiple types are passed to ....
+# However, with a method defined for all subclasses of Array, it will
+# do what a user expects most of the time.
Review comment:
_nods_ hmmmm yeah that is madness! And if we do define those extra
methods that were here before, does this madness go away? (e.g. if we do `c(
wk::xy(1:2, 1:2), Array$create(1:3))` what happens?)
If we still get weird errors there, I wonder if exposing `c()` is all that
helpful before we do it the "right way"?
We'll export our own concatenate method — so it's possible to use it, but I
suspect that `c()` working only when the first element is an array will be a
less-than-fun experience (with not too much upside anyway!).
--
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]