romainfrancois commented on a change in pull request #11898: URL: https://github.com/apache/arrow/pull/11898#discussion_r764896138
########## File path: r/R/array.R ########## @@ -187,7 +187,18 @@ Array$create <- function(x, type = NULL) { } return(out) } - vec_to_Array(x, type) + tryCatch( + vec_to_Array(x, type), + error = function(cnd) { + if (!is.null(type)) { + # try again and then cast + vec_to_Array(x, NULL)$cast(type) + } else { + signalCondition(cnd) + } + } + ) + Review comment: Another approach would be to hint about `$cast()`: - First try to do `vec_to_Array(x, type)` - If this fails and `type` was given, there is a chance that `vec_to_Array(x, NULL)$cast(type)` would work. The code could attempt it. - if we end up with an Array of `type` and then hint it, i.e. hint about doing `Array$create(x)$cast(type) - if not, just rethrow the original error Hinting places the decision of using casting on the user -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org