'Rcpp' Package Illustrating Header-Only Access to 'NLopt'

An example package which shows use of 'NLopt' functionality from C++ via 'Rcpp' without requiring linking, and relying just on 'nloptr' thanks to the exporting API added there by Jelmer Ypma. This package is a fully functioning, updated, and expanded version of the initial example by Julien Chiquet at < https://github.com/jchiquet/RcppArmadilloNLoptExample> also containing a large earlier pull request of mine.


RcppNLoptExample: Rcpp example of using NLopt via nloptr

CI License CRAN Downloads Last Commit

About

Starting with its 1.2.0 release, the nloptr package by Jelmer Ypma now exports its C symbols in a way that makes it accessible to other R packages without linking easing the installation across operating systems.

This package illustrates this with an example drawn from the NLopt tutorial.

Example

See the (currently single) file src/nlopt.cpp.

How / Why ?

R uses C interfaces. These C interfaces can be exported between packages. So when the usual library(nloptr) happens, we now also get a number of C functions registered.

And those are enough to run optimization from C++ as we simply rely on the C interface provided. Look careful at the example code: the objective function and the constraint functions are C functions, and the body of our example invokes C functions from NLopt. This just works.

On the other hand, if we tried to use the NLopt C++ interface which brings with it someinterface code we would require linking to that code (which R cannot easily export across packages using its C interface). So C it is.

See Also

This repo builds on, extends, and simplifies an earlier repo by Julien Chiquet to which I contributed a core part of this setup.

Author

Dirk Eddelbuettel

License

GPL (>= 2)

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("RcppNLoptExample")

0.0.2 by Dirk Eddelbuettel, 2 years ago


https://github.com/eddelbuettel/rcppnloptexample, https://dirk.eddelbuettel.com/code/rcpp.nloptexample.html


Report a bug at https://github.com/eddelbuettel/rcppnloptexample/issues


Browse source code at https://github.com/cran/RcppNLoptExample


Authors: Dirk Eddelbuettel [aut, cre]


Documentation:   PDF Manual  


GPL (>= 2) license


Imports Rcpp, nloptr

Linking to Rcpp, nloptr


See at CRAN