| Title: | 'Rcpp' Package Illustrating Header-Only Access to 'NLopt' |
|---|---|
| Description: | 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. |
| Authors: | Dirk Eddelbuettel [aut, cre] (ORCID: <https://orcid.org/0000-0001-6419-907X>) |
| Maintainer: | Dirk Eddelbuettel <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 0.0.2.2 |
| Built: | 2026-07-04 13:12:43 UTC |
| Source: | https://github.com/eddelbuettel/rcppnloptexample |
NLopt Version as Vector
nloptVersion()nloptVersion()
A list with an integer vector with three elements for major, minor
and patch release, classed as package_version and numeric_version.
nloptVersion()nloptVersion()
A simple example for for NLopt integration for Rcpp, using an example from the NLopt tutorial.
testProblem(method = "MMA", verbose = FALSE)testProblem(method = "MMA", verbose = FALSE)
method |
A string defaulting to ‘MMA’ (also allowing ‘COBYLA’) which selects the algorithm use. |
verbose |
A boolean toggle defaulting to ‘false’ |
This function illustrates use of NLopt from R without requiring linking. It relies on the set of exported functions the nloptr R package provides directly (and also instantiates) using a method described in Writing R Extensions. There is also a C++ interface to NLopt but it requires linking making use from another R package a little more involved as presence and location of the NLopt library may need to be checked (though using pkgconf can help).
A numeric vector with two elements
https://nlopt.readthedocs.io/en/latest/NLopt_Tutorial/
testProblem("MMA", TRUE)testProblem("MMA", TRUE)
Minimal wrapper for C++ function to illustrate logging from R
wrapper(method = "MMA")wrapper(method = "MMA")
method |
A string defaulting to ‘MMA’ (also allowing ‘COBYLA’) which selects the algorithm use. |
Nothing is returned as the function is invoked for its side effects.