romainfrancois commented on a change in pull request #8256:
URL: https://github.com/apache/arrow/pull/8256#discussion_r494775017
##########
File path: r/src/arrow_cpp11.h
##########
@@ -310,4 +312,32 @@ enable_if_enum<E, SEXP> as_sexp(E e) {
return as_sexp(static_cast<int>(e));
}
+template <typename T>
+SEXP R6_make(SEXP symbol, SEXP fun_symbol, const std::shared_ptr<T>& x) {
+ if (x == nullptr) {
+ return R_NilValue;
+ }
+ cpp11::external_pointer<std::shared_ptr<T>> xp(new std::shared_ptr<T>(x));
+
+ // make call: <symbol>$new(<x>)
+ SEXP call = PROTECT(Rf_lang3(R_DollarSymbol, symbol, fun_symbol));
+ SEXP call2 = PROTECT(Rf_lang2(call, xp));
+
+ // and then eval:
+ SEXP r6 = PROTECT(Rf_eval(call2, arrow::r::ns::arrow));
+
+ UNPROTECT(3);
+ return r6;
Review comment:
Perhaps this is more of a hypothetical `cpp11::call` thing, e.g.
```cpp
cpp11::call call(cpp11::call(R_DollarSymbol, symbol, fun_symbol), xp);
cpp11::sexp result = call.eval(arrow::r::ns::arrow);
```
Then I guess `cpp11::function` could factor out some of its logic in
`cpp11::call`
##########
File path: r/src/compute.cpp
##########
@@ -123,19 +123,19 @@ arrow::Datum as_cpp<arrow::Datum>(SEXP x) {
SEXP from_datum(arrow::Datum datum) {
Review comment:
Would that still do the dispatch internally before reaching the R side
or would there be an R6 class for `arrow::Datum`. Probably the latter.
##########
File path: r/R/compute.R
##########
@@ -127,15 +127,15 @@ match_arrow.Array <- function(x, table, ...) {
if (!inherits(table, c("Array", "ChunkedArray"))) {
table <- Array$create(table)
}
- Array$create(call_function("index_in_meta_binary", x, table))
+ call_function("index_in_meta_binary", x, table)
}
#' @export
match_arrow.ChunkedArray <- function(x, table, ...) {
if (!inherits(table, c("Array", "ChunkedArray"))) {
table <- Array$create(table)
}
- shared_ptr(ChunkedArray, call_function("index_in_meta_binary", x, table))
+ call_function("index_in_meta_binary", x, table)
}
Review comment:
We can go further when tackling this:
https://issues.apache.org/jira/browse/ARROW-10089
----------------------------------------------------------------
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:
[email protected]