The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.

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)

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.