[Rcpp-devel] Create and access several instances of a C++ class from R

soeren.vogel at uzh.ch soeren.vogel at uzh.ch
Fri May 13 16:11:36 CEST 2011


This posting continues the discussions from here:



Following all recommendations, we have rewritten our class to use STL. However, I have been trying around with various changes, but I can't get it working with RCPP_MODULES. Also, the code snippets posted by Romain Francois did not help since we cannot use inline, rather we need raw C++ code that can be compiled using R CMD BUILD etc. Therefore, I kindly ask the experts here for an example adaption to the source below. I guess you experts instantly see what needs to be done next to make the code working. Could you please give tips for the next step?

Thank you


/* FOO_mod.cpp */
#include <Rcpp.h>
#include <vector>
#include <valarray>
using namespace std;

// from FOO.h
class FOO
		double dtau;
		vector<double> D, ee, ff, S;

		int M;
		vector<double> C, t, s, par;
		vector<int> y;


		double do_bar(vector<double> z);

// from FOO.cpp
double FOO::do_bar(vector<double> z)
	// whatever it does

	using namespace Rcpp ;
	class_<FOO>( "FOO" )
		.field( "M" , &FOO::M )
		.field( "C" , &FOO::C )
		.method( "do_bar", &FOO::do_bar )

More information about the Rcpp-devel mailing list