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 <[email protected]> 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
> [email protected]
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>
_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to