"In short, this is not trivial."

No, it isn't. If you are not completely wedded to optimize(), I would suggest 
another route. Again, I recommend nlopt or some other package which has the 
algorithms you need. And you can investigate nloptr if you want to call the 
routines in that R package as Dirk pointed out below, and as in the list 
archives.

The C++ interface to nlopt uses std::vector. Using the facilities of Rcpp, I'm 
able to easily go from NumericVector to std::vector. This makes for very clean 
code.

FWIW, I'm implementing model prototypes in R, then re-implementing in C++ so I 
can then compare results via Rcpp. Thus, nlopt is a very good solution for me.

Dale Smith, Ph.D.
Senior Financial Quantitative Analyst
Financial & Risk Management Solutions
Fiserv
Office: 678-375-5315
www.fiserv.com

-----Original Message-----
From: rcpp-devel-boun...@r-forge.wu-wien.ac.at 
[mailto:rcpp-devel-boun...@r-forge.wu-wien.ac.at] On Behalf Of Dirk Eddelbuettel
Sent: Friday, February 28, 2014 7:14 AM
To: Gregor Kastner
Cc: rcpp-de...@r-forge.wu-wien.ac.at
Subject: Re: [Rcpp-devel] Rcpp syntactic sugar equivalent for R's optimize() 
function


On 28 February 2014 at 11:52, Gregor Kastner wrote:
| Hi Hideyoshi,
| 
| > Is there a way I can just call that function in Rcpp rather than 
| > having to install new libraries or create my own? (I presume that 
| > there is probably a “C_do_fmin.c” file somewhere that I can use?)
| 
| This questions has been discussed in this list about a month ago:
| 
| http://r.789695.n4.nabble.com/Linking-to-native-routines-in-other-pack
| ages-tt4683969.html#none

Not exactly. That question was about calling from another package for which the 
calling-registered-functions approach was discussed; Hideyoshi wants to call a 
function from an R base package.

That can be done, but can also be tricky because they don't exactly have the 
same calling interface:

  /* fmin(f, xmin, xmax tol) */
  SEXP do_fmin(SEXP call, SEXP op, SEXP args, SEXP rho)

It is a good exercise to work through the call, op, args arguments once :)

In short, this is not trivial. Which is why I chose to quickly reimplement / 
rewrite the Brent algorithm in another function for (internal, not
distributed) use as I alluded to in my earlier answer. 

Dirk

--
Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com 
_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to