Forget about .C. This is awkward. Perhaps using .Cover .Callor .Externalmade sense before Rcpp. But now with the work that we put in Rcpp, I no longer see the point in using it .C. Just use it .Call.
Even better, with attributes ( sourceCppand compileAttributes), you don’t even need to see anymore .Call, it just seems like you are using a C ++ function.
Now, if I wanted to do something that saves states, I would use a module. For example, your application is a class Test. It has methods do_somethingand do_something_else, and it counts the number of methods used:
#include <Rcpp.h>
using namespace Rcpp ;
class Test {
public:
Test(): count(0){}
void do_something(){
count++ ;
}
void do_something_else(){
count++ ;
}
int get_count(){
return count ;
}
private:
int count ;
} ;
++. , R, :
RCPP_MODULE(test){
class_<Test>( "Test" )
.constructor()
.method( "do_something", &Test::do_something )
.method( "do_something_else", &Test::do_something_else )
.property( "count", &Test::get_count )
;
}
:
app <- new( Test )
app$count
app$do_something()
app$do_something()
app$do_something_else()
app$count