[Rcpp-devel] How to put the code 2013-01-05-r-function-from-c++.cpp in the src/ directory of a package?

Peng Yu pengyu.ut at gmail.com
Sat May 25 21:21:25 CEST 2013


> Try   sourceCpp("somefile.cpp",  verbose=TRUE)   to see how the examples
> using Rcpp Attributes add an additional layer that deal with .Call and SEXP
> arguments.

Hi Dirk,

When I try to replicate the method used sourceCpp, I get the following
error. I'm not sure what is wrong. Would you please take a look how to
fix the error? Thanks.

~/dvcs_src/rexample/Rexample/cran/Rcpp/sourceCppFunction$ Rshl.sh main.cpp
llvm-g++-4.2 -arch x86_64 -dynamiclib -Wl,-headerpad_max_install_names
-undefined dynamic_lookup -single_module -multiply_defined suppress
-L/usr/local/lib -L/usr/local/lib -o main.so main.o
/Users/py/utility/R_user/Rcpp/lib/libRcpp.a
-F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework
-Wl,CoreFoundation
~/dvcs_src/rexample/Rexample/cran/Rcpp/sourceCppFunction$ Rscript main.R
> library(Rcpp)
> dl=dyn.load('main.so')
> callFunction=Rcpp:::sourceCppFunction(function(x, f) {}, FALSE, dl, 'callFunction')
>
> set.seed(42)
> x=rnorm(1e5)
> callFunction
function (x, f)
.Primitive(".Call")(<pointer: 0x103c73660>, x, f)
> callFunction(x, fivenum)
terminate called after throwing an instance of 'Rcpp::not_compatible'
  what():  cannot convert to function
Abort trap: 6

-- 
Regards,
Peng


More information about the Rcpp-devel mailing list