romainfrancois commented on a change in pull request #8246: URL: https://github.com/apache/arrow/pull/8246#discussion_r494166354
########## File path: r/src/arrow_cpp11.h ########## @@ -157,8 +157,15 @@ struct ns { template <typename Pointer> Pointer r6_to_pointer(SEXP self) { - return reinterpret_cast<Pointer>( - R_ExternalPtrAddr(Rf_findVarInFrame(self, arrow::r::symbols::xp))); + void* p = R_ExternalPtrAddr(Rf_findVarInFrame(self, arrow::r::symbols::xp)); + if (p == nullptr) { Review comment: Another way would be to have the ability to directly create the R6 objects internally, either by having more code in ```cpp template <typename T> SEXP as_sexp(const std::shared_ptr<T>& ptr) { return cpp11::external_pointer<std::shared_ptr<T>>(new std::shared_ptr<T>(ptr)); } ``` but we would need some sort of dispatch from `T` to the R6 object. Or we would need to change the interface of many functions: ```cpp // [[arrow::export]] std::shared_ptr<arrow::Array> StructArray__field( const std::shared_ptr<arrow::StructArray>& array, int i) { return array->field(i); } ``` perhaps to: ```cpp // [[arrow::export]] R6 StructArray__field( const std::shared_ptr<arrow::StructArray>& array, int i) { return R6(array->field(i), "Array"); } ``` but I don't think it's worth it ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org