> You. Are. Still. Doing. It. Wrong.

I know that I did was wrong. Otherwise it should have worked. What's
the point of reiterating it and emphasizing it? Something more
constructive is more helpful.

> Why did you think you'd need dyn.load?  Which of my posts to you had that?

Because dyn.load showed up in the output of sourceCpp(verbose=T) which
is mentioned in your previous email.

Anyway, here is the minimal code that I figured out. Rshl.sh is just a
wrapper for compiling the .so file when Rcpp is used in the source
code. And indeed dyn.load is needed.

~/dvcs_src/rexample/Rexample/cran/Rcpp/sourceCpp/decipher/sourceCppFunction$
cat main.R
library(Rcpp)
system('Rshl.sh callFunction.cpp')

callFunction=Rcpp:::sourceCppFunction(
        func=function(x, f) {}
        , isVoid=F
        , dll=dyn.load('callFunction.so')
        , symbol='callFunction'
        )

callFunction
set.seed(42)
x=rnorm(1e5)
fivenum(x)
callFunction(x, fivenum)

~/dvcs_src/rexample/Rexample/cran/Rcpp/sourceCpp/decipher/sourceCppFunction$
cat callFunction.cpp
#include <Rcpp.h>

using namespace Rcpp;
RcppExport SEXP callFunction(SEXP xSEXP, SEXP fSEXP) {
    NumericVector x = Rcpp::as<NumericVector>(xSEXP);
    Function f = Rcpp::as<Function>(fSEXP);
    NumericVector __result = f(x);
    return Rcpp::wrap(__result);
}
~/dvcs_src/rexample/Rexample/cran/Rcpp/sourceCpp/decipher/sourceCppFunction$
Rscript main.R
> library(Rcpp)
> system('Rshl.sh callFunction.cpp')
make: Nothing to be done for `all'.
>
> callFunction=Rcpp:::sourceCppFunction(
+       func=function(x, f) {}
+       , isVoid=F
+       , dll=dyn.load('callFunction.so')
+       , symbol='callFunction'
+       )
>
> callFunction
function (x, f)
.Primitive(".Call")(<pointer: 0x103c733c0>, x, f)
> set.seed(42)
> x=rnorm(1e5)
> fivenum(x)
[1] -4.043276349 -0.682384496 -0.002066374  0.673324712  4.328091274
> callFunction(x, fivenum)
[1] -4.043276349 -0.682384496 -0.002066374  0.673324712  4.328091274
>
>


-- 
Regards,
Peng
_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to