<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 30, 2016 at 8:23 AM, Whit Armstrong <span dir="ltr"><<a target="_blank" href="mailto:armstrong.whit@gmail.com">armstrong.whit@gmail.com</a>></span> wrote:<br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><div class="gmail-adM">



</div><div><div class="gmail-adM">
</div><div dir="ltr">My point regarding the clang parser is that one really shouldn't have to write any R or <span class="gmail-il">Rcpp</span> wrappers at all.
</div></div></blockquote></div><br></div><div class="gmail_extra">I realize this is a bit academic, but I suppose my position reduces to "RefClass + Rcpp = no wrappers at all".<br><br>For many (most?) people, a central point of Rcpp is to A) make things faster with minimal effort while B) still use R. RefClasses add native reference semantics to R, and one motivation for my original question is their relative newness.  Indeed, it looks like JMC did a big doc rework this Sept (<a href="https://github.com/wch/r-source/commits/trunk/src/library/methods/man/refClass.Rd">https://github.com/wch/r-source/commits/trunk/src/library/methods/man/refClass.Rd</a>). Of course, RefClasses aren't  as rich in, er, nuance as Cpp classes, but that may be a feature for many folks.<br><br>With this in mind, I assert that using a RefClass to define an object's data & methods, and then pushing "expensive" functionality to Cpp via Rcpp attributes, is the minimum possible "effort" required to (for expensive and effort suitably defined): A) achieve by-reference semantics using B) compiled-language speedup that C) doesn't mutate the args of user-facing functions.<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">One annoyance using  the RefClass + Rcpp approach is messy argument passing. With the Rcpp modules approach, Cpp data members of course need not  be passed to Cpp member functions  (though some still had to be set via R, of course). With a  RefClass, one possibility is to prepare one or more named lists to pass to Rcpp functions. These lists   then, kinda-sorta, fill the role of a cpp class's self pointer.<br><br>I wrote up a minimal example to verify that this approach isn't too costly. It's too painfully simple to test *much*, but it perhaps provides a useful starting point:<br><a href="https://github.com/helmingstay/test_code/tree/master/convolver">https://github.com/helmingstay/test_code/tree/master/convolver</a><br><br>For production code, my thought is to prep the relevant lists during initialize() and then lock() them... I haven't gotten there yet :)<br><br></div><div class="gmail_extra">-Christian<br clear="all"></div><div class="gmail_extra"><br>-- <br><div class="gmail_signature">A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal – Panama!</div>
</div></div>