SEXP __sexp_result;
PROTECT(__sexp_result = Rcpp::wrap(params_r));
UNPROTECT(1);
return __sexp_result;
With Rcpp I've always just been able to return objects to R by doing:
return Rcpp::wrap(params_r);
With a few exceptions this works for me (no segfaults/etc...). This is also what the Rcpp book and vignette recommend, from the vignette:
The RObject class takes advantage of the explicit life cycle of
C++ objects to manage ex-posure of the underlying R object to the garbage collector. The RObject effectively treats its underlying SEXP as a resource. The constructor of the RObject class takes the necessary measures to guarantee that the underlying SEXP is protected from the garbage collector, and
the destructor assumes the responsibility to withdraw that protection.
By assuming the entire responsibility of garbage collection,
Rcpp relieves the programmer from writing boiler plate code to manage the protection stack with PROTECT and UNPROTECT macros
I never got into programming with C/R before Rcpp came around so I'm not sure if there's some additional motivation here but it's confusing (me).
Krzysztof
--
You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.