I am having some trouble working through the examples inside:
http://dirk.eddelbuettel.com/code/rcpp/Rcpp-modules.pdf
Specifically, section 2.2 where the author goes to expose a C++ class in RCPP and making it available to call in R.
I copied the code in to a new RCPP file and sourced it with no problem but got an error when I ran the following in R:
require(Rcpp)
require(inline)
unif_module <- Module( "unif_module", getDynLib(fx_unif ) )
The error:
Error in getDynLib(fx_unif) :
error in evaluating the argument 'x' in selecting a method for function 'getDynLib': Error: object 'fx_unif' not found
I then went though the other parts of the document where getDynLib
is used and found that none of them initialized the arguments passed in to getDynLib
. My question is what is fx_unif
?
Thanks,
Update:
So following another example within the paper i tried:
inc = '
class Uniform {
public:
Uniform(double min_, double max_) : min(min_), max(max_) {}
NumericVector draw(int n) const {
RNGScope scope;
return runif( n, min, max );
}
double min, max;
};
double uniformRange( Uniform* w) {
return w->max - w->min;
}
RCPP_MODULE(unif_module) {
class_<Uniform>( "Uniform" )
.constructor<double,double>()
.field( "min", &Uniform::min )
.field( "max", &Uniform::max )
.method( "draw", &Uniform::draw )
.method( "range", &uniformRange )
;
}
'
fx_unif = cxxfunction(signature(), plugin="Rcpp", include=inc)
error:
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! Warning message:
running command 'make -f "C:/PROGRA~1/R/R-32~1.2/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-32~1.2/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="filef4028245a6f.dll" WIN=64 TCLBIN=64 OBJECTS="filef4028245a6f.o"' had status 127
In addition: Warning message:
running command 'C:/PROGRA~1/R/R-32~1.2/bin/x64/R CMD SHLIB filef4028245a6f.cpp 2> filef4028245a6f.cpp.err.txt' had status 1