Would it be useful to consider using the Function class in Rcpp? You can pass R functions in as arguments like so;<br><br>library(inline)<br>library(Rcpp)<br><br>example <- cxxfunction(signature(f_ = "Function"), body = '<br>

                Rcpp::Function f(f_);<br>                Rcpp::NumericVector out = f(10, 1);<br>                return out;<br>                ', plugin = "Rcpp")<br><br>> example(rpois)<br> [1] 2 0 1 3 1 1 1 0 1 0<br>

<br>Obviously you wouldn't want to pass R's rpois function in (as this is already implement in Rcpp Sugar) but hopefully the example will make sense. <br><br>Jeff<br><br><div class="gmail_quote">On Fri, Sep 28, 2012 at 5:05 AM,  <span dir="ltr"><<a href="mailto:Dan.Pagendam@csiro.au" target="_blank">Dan.Pagendam@csiro.au</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Apologies, in the previous email I meant to say:<br>
<br>
 "Is it possible for me to have my cxxfunction instantiate an object of class RInside within the C++ code?"<br>
<br>
NOT<br>
<div class="im"><br>
"Is it possible for me to have my cxxfunction instantiate an object of class RInline within the C++ code?"<br>
<br>
<br>
</div><div class="im">Dr Dan Pagendam<br>
OCE Postdoctoral Research Fellow<br>
CSIRO Mathematics, Informatics and Statistics<br>
<br>
Phone: <a href="tel:%2B61%207%203833%205535" value="+61738335535">+61 7 3833 5535</a> | Mobile: <a href="tel:%2B61%204%203295%208551" value="+61432958551">+61 4 3295 8551</a><br>
Email: Dan.Pagendam@csiro.au<mailto:<a href="mailto:Dan.Pagendam@csiro.au">Dan.Pagendam@csiro.au</a>><mailto:<a href="mailto:Dan.Pagendam@csiro.au">Dan.Pagendam@csiro.au</a><mailto:<a href="mailto:Dan.Pagendam@csiro.au">Dan.Pagendam@csiro.au</a>>> | <a href="http://www.csiro.au" target="_blank">http://www.csiro.au</a><br>


Postal Address: CSIRO Mathematics Informatics and Statistics, EcoSciences Precinct, PO Box 2583, Brisbane, QLD 4001<br>
Street Address: CSIRO Mathematics Informatics and Statistics, EcoSciences Precinct, 41 Boggo Road, Dutton Park, QLD 4102<br>
<br>
<br>
<br>
</div><div class="im">On 28/09/2012, at 1:48 PM, <Dan.Pagendam@csiro.au<mailto:<a href="mailto:Dan.Pagendam@csiro.au">Dan.Pagendam@csiro.au</a>>> wrote:<br>
<br>
Hi,<br>
<br>
this is my first post here.  I've just started to explore the uses of Rcpp, Inline and RInside and must say that I think these are really fantastic tools, which I hope to use routinely in the future.<br>
<br>
I'm about to embark on writing some code, but before I do, I was hoping somebody can offer a quick "sanity check" for me and let me know if what I am proposing is achievable and sensible.<br>
<br>
Bascially, I would like to write a cxxfunction in R using Rcpp and Inline so that I can execute my C++ code easily from within R.  However, I'd like my C++ code comprising the cxxfunction to make use of the R language too.  Is it possible for me to have my cxxfunction instantiate an object of class RInline within the C++ code?  I guess what I'm getting at is, can I get R to call on a C++ function which in turn calls upon R code?<br>


<br>
I've looked at plenty of examples of code that use RInline and it seems that they are all just based around calling on R from with C++.  This is making me wonder if what I am suggesting above is either plain dumb or just not possible.<br>


<br>
Thanks in advance for your help,<br>
<br>
Dan<br>
<br>
Dr Dan Pagendam<br>
OCE Postdoctoral Research Fellow<br>
CSIRO Mathematics, Informatics and Statistics<br>
<br>
Phone: <a href="tel:%2B61%207%203833%205535" value="+61738335535">+61 7 3833 5535</a> | Mobile: <a href="tel:%2B61%204%203295%208551" value="+61432958551">+61 4 3295 8551</a><br>
</div>Email: Dan.Pagendam@csiro.au<mailto:<a href="mailto:Dan.Pagendam@csiro.au">Dan.Pagendam@csiro.au</a>><mailto:<a href="mailto:Dan.Pagendam@csiro.au">Dan.Pagendam@csiro.au</a>><mailto:<a href="mailto:Dan.Pagendam@csiro.au">Dan.Pagendam@csiro.au</a><mailto:<a href="mailto:Dan.Pagendam@csiro.au">Dan.Pagendam@csiro.au</a>>> | <a href="http://www.csiro.au" target="_blank">http://www.csiro.au</a><br>


<div class="im">Postal Address: CSIRO Mathematics Informatics and Statistics, EcoSciences Precinct, PO Box 2583, Brisbane, QLD 4001<br>
Street Address: CSIRO Mathematics Informatics and Statistics, EcoSciences Precinct, 41 Boggo Road, Dutton Park, QLD 4102<br>
<br>
<br>
<br>
_______________________________________________<br>
Rcpp-devel mailing list<br>
</div><a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><mailto:<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a>><br>


<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
<div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
</div></div></blockquote></div><br>