paleolimbot commented on code in PR #12817:
URL: https://github.com/apache/arrow/pull/12817#discussion_r852237357
##########
r/R/type.R:
##########
@@ -69,16 +70,43 @@ FLOAT_TYPES <- c("float16", "float32", "float64",
"halffloat", "float", "double"
#' type(mtcars)
#' type(Sys.Date())
#' @export
-type <- function(x) UseMethod("type")
+type <- function(x, ...) UseMethod("type")
#' @export
-type.default <- function(x) Array__infer_type(x)
+type.default <- function(x, ..., from_array_infer_type = FALSE) {
+ # If from_array_infer_type is TRUE, this is a call from C++ and there was
+ # no S3 method defined for this object.
+ if (from_array_infer_type) {
+ abort(
+ sprintf(
+ "Can't infer Arrow data type from object inheriting from %s",
+ paste(class(x), collapse = " / ")
+ )
+ )
+ }
+
+ # If from_array_infer_type is FALSE, this is a user calling type() from R
+ # and we to call into C++. If there is no built-in conversion for this
+ # object type, C++ will call back here with from_array_infer_type = TRUE
Review Comment:
See the above note about `as_arrow_array()`, except the C++ functions
involved are `InferSchemaFromDots` (which gets called by e.g.
`Table___from_dots()`). After getting all the tests to pass I also had the
thought of "there has to be a way to make this simpler!", although to do so
some changes would be required in the existing conversion pathways (and I was
trying specifically to avoid changing those to minimize the scope of this PR).
--
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]