title: Problems installing R package "nloptr" on M1 mac
body: <p>I'm trying to install the &quot;lme4&quot; library in R and RStudio, which worked before I was on an M1 Mac, but now it's not installing. The dependency that's having trouble is: &quot;nloptr&quot;. Here's my current error:</p>
  <pre><code>clang++ -arch arm64 -std=gnu++11 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/opt/R/arm64/lib -o nloptr.so init_nloptr.o nloptr.o test-C-API.o test-runner.o -L/Library/Frameworks/R.framework/Resources/lib -lRlapack -L/Library/Frameworks/R.framework/Resources/lib -lRblas -L/opt/R/arm64/gfortran/lib/gcc/aarch64-apple-darwin20.2.0/11.0.0 -L/opt/R/arm64/gfortran/lib -lgfortran -lemutls_w -lm -Lnlopt/lib -lnlopt -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
  ld: warning: directory not found for option '-Lnlopt/lib'
  ld: library not found for -lnlopt
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  make: *** [nloptr.so] Error 1
  ERROR: compilation failed for package ‘nloptr’
  * removing ‘/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/nloptr’
  Warning in install.packages :
    installation of package ‘nloptr’ had non-zero exit status
  
  The downloaded source packages are in
      ‘/private/var/folders/ht/y6qd6yfn67x086jtwxvh42tw0000gn/T/RtmpULtpZq/downloaded_packages’ ```
  </code></pre>
  <p>I'm on an M1 Mac with Monterey (12.1). I've installed the arm64 version of R. Here's my current version R 4.1.2:</p>
  <pre><code>&gt; version
                 _                           
  platform       aarch64-apple-darwin20      
  arch           aarch64                     
  os             darwin20                    
  system         aarch64, darwin20           
  status                                     
  major          4                           
  minor          1.2                         
  year           2021                        
  month          11                          
  day            01                          
  svn rev        81115                       
  language       R                           
  version.string R version 4.1.2 (2021-11-01)
  nickname       Bird Hippie    
  </code></pre>
  <p>I've already tried the following in Terminal: <code>brew install nlopt</code> and <code>brew install gcc</code>.</p>
  <p>Before this, I also had an error as follows:
  <code>ld: warning: directory not found for option '-L/opt/R/arm64/gfortran/lib/gcc/aarch64-apple-darwin20.2.0/11.0.0'</code>
  To fix that, based on Googling, I did this
  <code>export PATH=$PATH:/opt/R/arm64/gfortran/bin</code>
  and this
  <code>ln -sfn `xcrun --show-sdk-path` /opt/R/arm64/gfortran/SDK</code></p>