[Rcpp-devel] Linking problem when wrapping a armadillo-based C++ library in a R package using RcppArmadillo

julien chiquet julien.chiquet at gmail.com
Thu Jul 26 17:06:53 CEST 2018

On Thu, Jul 26, 2018 at 3:09 PM Dirk Eddelbuettel <edd at debian.org> wrote:

> So can you detail why the working example from nloptr does not suffice for
> you?  Because Jelmer has still not released that nloptr version to CRAN?
> Or
> is there another reason?

Ok let's try an answer...  there are several reasons.

As a researcher in (computational) statistics, I need to get access to
efficient, scalable  optimization methods to fit some new statistical
models. It seems natural to me to try an check any new fancy solution
provided by the community, like the one offered by Keith. Moreover, I also
often need to tune a bit the optimization algorithms at play for my
particular problems: the solution offered by Keith, which uses armadillo,
is great because it makes writing C++ code (and especially algebra) so easy
even for a statistician. I also always like to check if some particular
implementation is more robust or faster than another.

You could answer me that nloptr also offers an interface to armadillo with
the solution that you provided : that is right, and thank you again for
that ! However, there is an optimization method from the orignal NLOPT
library (called CCSA) working well for a particular problem that I have
(see the git repo https://github.com/jchiquet/PLNmodels) which is curiously
not exported in nloptr. I thus chose to develop this particular R package
by asking the user to install a system nlopt during the install process on
R via a config file (eg. via message asking for apt-get install
libnlopt-dev for Linux or brew install for Mac OS and... sorry for Windows
users for now). Then I can link directly to the system nlopt to get access
to the headers and to the CCSA algorithm. I also like this solution because
it bypasses R during the optimisation process (calling many times objective
and gradient functions) and thus avoids overheads implied by calls to R
functions. But in that case the time saved is not so impressive, so if
Jelmer finally put an updated version with both export to C++ headers and
CCSA algorithm, I would go back to nloptr R to help the portability
(especially for Windows users). CRAN or github is not and problem to me as
long as the R package and the associated stat method are at a "research"

And a final reason: I also wanted to learn how to properly wrap a C++
library in a R package, an I thought that the optim package from Keith was
a good opportunity for this, that could eventually help the community a bit.



> Dirk
> --
> http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20180726/aa1356c8/attachment.html>

More information about the Rcpp-devel mailing list