paleolimbot commented on code in PR #12817:
URL: https://github.com/apache/arrow/pull/12817#discussion_r855205407


##########
r/src/arrow_types.h:
##########
@@ -100,6 +127,35 @@ std::shared_ptr<arrow::DataType> InferArrowType(SEXP x);
 std::shared_ptr<arrow::Array> vec_to_arrow__reuse_memory(SEXP x);
 bool can_reuse_memory(SEXP x, const std::shared_ptr<arrow::DataType>& type);
 
+// These are the types of objects whose conversion to Arrow Arrays is handled
+// entirely in C++. Other types of objects are converted using the
+// infer_type() S3 generic and the as_arrow_array() S3 generic.
+// For data.frame, we need to recurse because the internal conversion
+// can't accomodate calling into R. If the user specifies a target type
+// and that target type is an ExtensionType, we also can't convert
+// natively (but we check for this separately when it applies).
+static inline bool can_convert_native(SEXP x) {
+  if (!Rf_isObject(x)) {

Review Comment:
   Anything with a `class()` attribute (although my understanding is that 
internally R maintains an "object" bitflag when setting/removing the class 
attribute, so this test is fast):
   
   ``` r
   cpp11::cpp_function("bool is_object(sexp obj) { return Rf_isObject(obj); }")
   is_object(1)
   #> [1] FALSE
   is_object(structure(1, class = "something"))
   #> [1] TRUE
   ```
   
   There might be a type that we haven't considered here (complex maybe?), but 
for the most part we had already implemented conversions for all the base R 
types.



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