dragosmg commented on a change in pull request #11898:
URL: https://github.com/apache/arrow/pull/11898#discussion_r765657581



##########
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:
       The `tryCatch(...)` now looks like this and I think it's a step in the 
right direction:
   ```
   tryCatch(
       vec_to_Array(x, type),
       error = function(cnd) {
         attempt <- try(vec_to_Array(x, NULL)$cast(type), silent = TRUE)
         if (!inherits(attempt, "try-error")) {
           message("Hint: You might want to try casting manually. Something 
like `Array$create(...)$cast(...)`")
         }
         stop(conditionMessage(cnd), call. = FALSE)
       }
     )
     ```




-- 
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]


Reply via email to