thisisnic commented on a change in pull request #10269:
URL: https://github.com/apache/arrow/pull/10269#discussion_r648045038
##########
File path: r/R/util.R
##########
@@ -139,3 +139,42 @@ attr(is_writable_table, "fail") <- function(call, env){
)
}
+#' Take an object of length 1 and repeat it.
+#'
+#' @param object Object of length 1 to be repeated - vector, `Scalar`,
`Array`, or `ChunkedArray`
+#' @param n Number of repetitions
+#'
+#' @return `Array` of length `n`
+#'
+#' @keywords internal
+repeat_value_as_array <- function(object, n) {
+ if (inherits(object, "ChunkedArray")) {
+ return(Scalar$create(object$chunks[[1]])$as_array(n))
+ }
+ return(Scalar$create(object)$as_array(n))
+}
+
+#' Recycle scalar values in a list of arrays
+#'
+#' @param arrays List of arrays
+#' @return List of arrays with any vector/Scalar/Array/ChunkedArray values of
length 1 recycled
+#' @keywords internal
+recycle_scalars <- function(arrays){
+ # Get lengths of items in arrays
+ arr_lens <- map_int(arrays, NROW)
+
+ if (length(arrays) > 1 && any(arr_lens == 1) && !all(arr_lens==1)) {
+
+ # Recycling not supported for tibbles and data.frames
+ if(all(map_lgl(arrays, ~inherits(.x, "data.frame")))){
+ abort(c(
+ "All input tibbles or data.frames must have the same number of rows",
+ x = paste("Number of rows in inputs:",oxford_paste(map_int(arrays,
~nrow(.x))))
Review comment:
I wasn't before, but now I am now you mention it. I have updated my
error message to just print the longest and shortest length items seeing as I
think this is still sufficient to be useful. Let me know if it looks OK!
--
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]