-1

I'm trying to find an Rcpp replacement for the base optimize function. This link https://github.com/eddelbuettel/rcppnloptexample/blob/master/src/nlopt.cpp

is a potential solution but I can't get past the sourceCpp error

Error in Rcpp::sourceCpp("R/nlopt.cpp") : 
  Error 1 occurred building shared library.
> library('nloptr')
> Rcpp::sourceCpp("R/nlopt.cpp")
nlopt.cpp:4:10: fatal error: 'nloptrAPI.h' file not found

The header file is in fact on my computer at /Library/Frameworks/R.framework/Versions/4.1/Resources/library/nloptr/include

I can include the whole path to the header and it seems to work fine but that seems a bit kludgy.

What do I need to do to tell R or Rcpp where to look?

JerryN
  • 2,356
  • 1
  • 15
  • 49

1 Answers1

-1

This link as some useful discussion about the issue of finding headers. https://stackoverflow.com/questions/13995266/using-3rd-party-header-files-with-rcpp has useful information.

To find out where your 'missing' header is located, the /Library/Frameworks ... link above is useful, replacing nloptr with the name of the package that has the header you are looking for.

JerryN
  • 2,356
  • 1
  • 15
  • 49