<P>Dear list first of all happy new year.<BR>I have a question .. I would like to call rcpp function  (so c++ function) into <BR>R function (optim for example) called into rcpp. I had prototype an example code and post <BR>below.  (Using Rcpp::InternalFunction(&foo))<BR>Is it correct the way I had used? There is another more efficient and safety way <BR>Thank You in advance list <BR>Best regards<BR>Gianluca Bonitta</P>
<P><BR>library(inline)</P>
<P>inc <- ' NumericVector foo(const Rcpp::NumericVector &x) { <BR>        return - pow(x,2);<BR>                        } '<BR>code<- '<BR>   Rcpp:: NumericVector start(Sexp_start);<BR>   Rcpp:: Environment stats("package:stats"); <BR>   Rcpp:: Function optim = stats["optim"];    <BR>   Rcpp:: List Opt;</P>
<P>   Opt=optim(_["par"]     = start,<BR>             _["fn"]      = <FONT color=#ff0000>Rcpp::InternalFunction(&foo),<BR></FONT>             _["method"]  = "BFGS");<BR>return Opt;<BR>'<BR>fun.cpp <- cxxfunction(signature( Sexp_start = "NumericVector"),<BR>                                           code, <BR>                                           include    = inc,<BR>                                           plugin     = "Rcpp" )<BR>fun.cpp (Sexp_start=0.1)</P>
<P>#### R code ####<BR>fun. <- function(x) x^2<BR>optim(0.1,fun.,method  = "BFGS") </P>