You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2020/09/25 06:31:39 UTC

[GitHub] [arrow] romainfrancois commented on a change in pull request #8256: ARROW-9001: [R] Box outputs as correct type in call_function

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` 
   




----------------------------------------------------------------
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:
users@infra.apache.org