ianmcook commented on a change in pull request #10269:
URL: https://github.com/apache/arrow/pull/10269#discussion_r629634210
##########
File path: r/R/record-batch.R
##########
@@ -161,6 +161,17 @@ RecordBatch$create <- function(..., schema = NULL) {
out <- RecordBatch__from_arrays(schema, arrays)
return(dplyr::group_by(out, !!!dplyr::groups(arrays[[1]])))
}
+
+ # If any arrays are length 1, recycle them
+ arr_lens <- map_int(arrays, length)
+ if (length(arrays) > 1 && any(arr_lens == 1) && !all(arr_lens==1)){
+ max_array_len <- max(arr_lens)
+ arrays <- modify2(
+ arrays,
+ arr_lens == 1,
+ ~if(.y) MakeArrayFromScalar(Scalar$create(as.vector(.x)), max_array_len)
else .x
Review comment:
As for how to convert a `ChunkedArray` to an `Array`: you should add a
new R6 method named `combine_chunks()` to the `ChunkedArray` class that works
like the PyArrow
[`ChunkedArray.combine_chunks`](https://arrow.apache.org/docs/python/generated/pyarrow.ChunkedArray.html#pyarrow.ChunkedArray.combine_chunks)
method (but without the MemoryPool stuff).
That in turn will require adding a `concat_arrays()` function (like PyArrow
has) which could be exported.
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]