jonkeane commented on a change in pull request #10601:
URL: https://github.com/apache/arrow/pull/10601#discussion_r658849841



##########
File path: r/R/metadata.R
##########
@@ -56,7 +56,21 @@ apply_arrow_r_metadata <- function(x, r_metadata) {
     if (is.data.frame(x)) {
       if (length(names(x)) && !is.null(columns_metadata)) {
         for (name in intersect(names(columns_metadata), names(x))) {
-          x[[name]] <- apply_arrow_r_metadata(x[[name]], 
columns_metadata[[name]])
+          x[[name]] <- tryCatch({
+            x[[name]] <- apply_arrow_r_metadata(x[[name]], 
columns_metadata[[name]])
+          },
+          error = function(e) {
+            # if we are erroring because of incompatible data, try and make 
this
+            # a tibble
+            # TODO: also check if this is a list?
+            # TODO: only if there are exactly as many sub-list elements as 
rows?
+            # TODO: decide if this obviates the need for the option
+            #   arrow.strucs_as_dfs (or if that is actually a better way to 
handle that)
+            if (grepl("must be compatible with existing data", e$message))
+              x[[name]] <- as.data.frame(x[[name]])
+              class(x[[name]]) <-  c("tbl_df", "tbl", "data.frame")
+              apply_arrow_r_metadata(x[[name]], columns_metadata[[name]])
+          })

Review comment:
       This works along side the option restore-old-behavior I point out below. 
I don't think this could totally replace it. Though if we don't go this route 
maybe in the invalid message here we should mention trying to re-read with that 
option set




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


Reply via email to