<font face="arial, helvetica, sans-serif">If you compile it from within R using sourceCpp("cpp_<span class="final-path" style="margin:0px;padding:0px;border:0px;line-height:25px;background-color:rgb(255,255,255)">file_name.cpp</span><span style="color:rgb(153,153,153);line-height:25px;background-color:rgb(255,255,255)"> </span>"). Or if you use the package inline, you can do the following inside R.</font><div>

<font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><div>cppFunction('</div><div>      NumericVector callFunction(NumericVector x, Function f) {</div><div>           NumericVector res = f(x);</div>

<div>           return res;</div><div>     }'</div><div> )</div><div><br></div></font><div><span style="font-family:arial,helvetica,sans-serif">Both methods let you directly call the function callFunction(x, f) (without having to use .Call())</span></div>

<div><br></div><div><font face="arial, helvetica, sans-serif">callFunction(rnorm(30), sum)</font></div><div><div><br></div><div><br></div><div><div><br></div><div><br><br><div class="gmail_quote">On Thu, May 23, 2013 at 9:14 PM, Peng Yu <span dir="ltr"><<a href="mailto:pengyu.ut@gmail.com" target="_blank">pengyu.ut@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I'm able to compile 2013-01-05-r-function-from-c++.cpp to the .so<br>
file. But I'm not able to call "callFunction" in R does anybody know<br>
what the correct way is to call R functions in C++? Thanks.<br>
<br>
> dyn.load('2013-01-05-r-function-from-c++.so')<br>
> x <- rnorm(1e5)<br>
> .Call('callFunction', x, fivenum)<br>
Error in .Call("callFunction", x, fivenum) :<br>
  C symbol name "callFunction" not in load table<br>
> callFunction(x, fivenum)<br>
Error: could not find function "callFunction"<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Regards,<br>
Peng<br>
_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
</font></span></blockquote></div><br></div></div></div></div>