[Rcpp-devel] how to create an Rcpp::List in a standalone C++ application?

Dirk Eddelbuettel edd at debian.org
Wed Dec 18 13:51:00 CET 2013

Hi Florian,

On 18 December 2013 at 11:12, Florian Oswald wrote:
| I have a C++ class that I build and test without the help of Rcpp. 
| I use Rcpp as an interface, inputting and outputting data from and to the
| class. I'm stuck at the outputter. Ideally I would like to have this at the end
| of my program:
| Rcpp::List Results = MyClass.ExportToR();
| where ExportToR is a method that creates an Rcpp::List from members of MyClass.
| However, I'm unable to use components of Rcpp.h in my code; In particular, I'm

If you want to use R in your own main, use  RInside  which makes this
trivial. We ship it with several dozen examples.

If you want to return a generic list structure, use the eg the STL type list
(or, as you are using Blitz, maybe one of its containers).

| unable to make this toy example work:
| #include <iostream>
| #include <cstdlib>
| #include <blitz/array.h>
| #include <Rcpp.h>
| #include <R.h>
| using namespace std;
| int main(int argc, char *argv[])
| {
|   Rcpp::IntegerVector d;
|   // Rcpp::List L; want to use
|   // L to output results to R.
|  return EXIT_SUCCESS;
| }
| I compile it with
| llvm-g++-4.2 -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include
| -DNDEBUG -W -I/usr/local/include -I/usr/local/include -I"/Library/Frameworks/
| R.framework/Versions/3.0/Resources/library/Rcpp/include" -L"/Library/Frameworks
| /R.framework/Versions/3.0/Resources/library/Rcpp/lib/" -L"/Library/Frameworks/
| R.framework/Versions/3.0/Resources/lib" export.cpp -lRcpp -lR -o  export
| which compiles, but produces a segfault.

To be expected. R is its own main program, you cannot mix as you did. I
suspect you may find RInside useful; it deploys all of Rcpp for parameter

Cheers. Dirk

| Thanks for any help!
| Florian
| ----------------------------------------------------------------------
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com

More information about the Rcpp-devel mailing list