How can I deal with this nloptr error in R?

2.4k views Asked by At
init_nloptr.c:35:10: fatal error: 'nlopt.h' file not found
#include "nlopt.h"
         ^~~~~~~~~
1 error generated.
make: *** [init_nloptr.o] Error 1
ERROR: compilation failed for package 'nloptr'
* removing '/Library/Frameworks/R.framework/Versions/3.5/Resources/library/nloptr'
Warning in install.packages :
  installation of package 'nloptr' had non-zero exit status
I got this error message when I installed nloptr package which need to install mi package.
1

There are 1 answers

0
AlessioX On

From the path showing up in the error message, it looks like you're running on macOS.

If so, you must install the nlopt system library before installing nloptr.

Hopefully you have Homebrew installed (if not, please reply/comment and I will attach some further info), hence open the Terminal and run

brew install nlopt

At the end of the brew install command, go back to R and install nloptr.