[Rcpp-devel] Newbie question: RInside from within a Inline/Rcpp cxxfunction

Dirk Eddelbuettel edd at debian.org
Fri Sep 28 16:38:21 CEST 2012


Hi Dan,

Welcome to list.

On 28 September 2012 at 13:48, Dan.Pagendam at csiro.au wrote:
| 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?
| 
| 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.

The latter.

RIinside is for when you have a C++ program with 'int main(argc, argv)' to
which you want to add R.  [ I do not know how/where to make that more plain,
but it seems I need to. Suggestions welcome. ]

Rcpp is for when you want to extend R (which supplies its main() function).

The two are _very_ distinct use cases.

As Jeff P. just pointed out, you can call R functions from Rcpp code.  That
doesn't mean you should repeatedly -- there will be performance penalties.
But for the occassional initialization or conversion or ... it is perfectly.

It is also shown as part of the numerous examples that comes with Rcpp.  Rcpp
(and RInside) is pretty rich topic and there is lots of documentation. Keep
looking.  The list archives are also pretty fertile, and Google (via
rseek.org) is surely your friend.

Dirk

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com  


More information about the Rcpp-devel mailing list