[Rcpp-devel] How to use https://github.com/jjallaire/rcpp-gallery/blob/gh-pages/src/2013-01-05-r-function-from-c++.cpp?

Xiao He praguewatermelon at gmail.com
Fri May 24 06:27:42 CEST 2013


If you compile it from within R using sourceCpp("cpp_file_name.cpp "). Or
if you use the package inline, you can do the following inside R.

cppFunction('
      NumericVector callFunction(NumericVector x, Function f) {
           NumericVector res = f(x);
           return res;
     }'
 )

Both methods let you directly call the function callFunction(x, f) (without
having to use .Call())

callFunction(rnorm(30), sum)





On Thu, May 23, 2013 at 9:14 PM, Peng Yu <pengyu.ut at gmail.com> wrote:

> Hi,
>
> I'm able to compile 2013-01-05-r-function-from-c++.cpp to the .so
> file. But I'm not able to call "callFunction" in R does anybody know
> what the correct way is to call R functions in C++? Thanks.
>
> > dyn.load('2013-01-05-r-function-from-c++.so')
> > x <- rnorm(1e5)
> > .Call('callFunction', x, fivenum)
> Error in .Call("callFunction", x, fivenum) :
>   C symbol name "callFunction" not in load table
> > callFunction(x, fivenum)
> Error: could not find function "callFunction"
>
> --
> Regards,
> Peng
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130523/23640d34/attachment-0001.html>


More information about the Rcpp-devel mailing list