Rstudio can't find CMAKE even though it is in /usr/local/bin

I have been attempting to install a package that requires cmake. However, Rstudio can't seem to find it for some reason:

R version 4.3.1 (2023-06-16) -- "Beagle Scouts"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin22.4.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> file.exists("/usr/local/bin/cmake")
[1] TRUE

> install.packages("nloptr")
Installing package into ‘/usr/local/lib/R/4.3/site-library’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/nloptr_2.0.3.tar.gz'
Content type 'application/x-gzip' length 2219877 bytes (2.1 MB)
==================================================
downloaded 2.1 MB

* installing *source* package ‘nloptr’ ...
** package ‘nloptr’ successfully unpacked and MD5 sums checked
** using staged installation
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C++... yes
checking whether clang++ -std=gnu++17 accepts -g... yes
checking for clang++ -std=gnu++17 option to enable C++11 features... none needed
checking how to run the C++ preprocessor... clang++ -std=gnu++17 -E
checking whether the compiler supports GNU C++... (cached) yes
checking whether clang++ -std=gnu++17 accepts -g... (cached) yes
checking for clang++ -std=gnu++17 option to enable C++11 features... (cached) none needed
checking for pkg-config... /usr/local/bin/pkg-config
checking if pkg-config knows NLopt... no
checking for cmake... /usr/local/bin/cmake
using NLopt via local cmake build on x86_64 

------------------ CMAKE NOT FOUND --------------------

CMake was not found on the PATH. Please install CMake:

 - sudo yum install cmake          (Fedora/CentOS; inside a terminal)
 - sudo apt install cmake          (Debian/Ubuntu; inside a terminal).
 - sudo pacman -S cmake            (Arch Linux; inside a terminal).
 - sudo brew install cmake         (MacOS; inside a terminal with Homebrew)
 - sudo port install cmake         (MacOS; inside a terminal with MacPorts)

Alternatively install CMake from: <https://cmake.org/>

-------------------------------------------------------

Here is my session info and System Environment info:

> sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: x86_64-apple-darwin22.4.0 (64-bit)
Running under: macOS Ventura 13.4.1

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /usr/local/Cellar/r/4.3.1/lib/R/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Los_Angeles
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_4.3.1 tools_4.3.1   
> Sys.getenv()
__CF_USER_TEXT_ENCODING
                       0x1F5:0x0:0x0
__CFBundleIdentifier   com.rstudio.desktop
CENSUS_API_KEY         fb091da47796bffbc135ba2c890926587bf3e54d
CLICOLOR_FORCE         1
COMMAND_MODE           unix2003
DISPLAY                /private/tmp/com.apple.launchd.Y4J4MMGXa6/org.xquartz:0
EDITOR                 vi
GIT_ASKPASS            rpostback-askpass
GITHUB_PAT             668cc686430fd7ce9d4ed299eddbff3f2ffc85e5
HOME                   /Users/adamelder
LANG                   en_US.UTF-8
LC_CTYPE               en_US.UTF-8
LN_S                   ln -s
LOGNAME                adamelder
MAKE                   make
MallocNanoZone         0
MPLENGINE              tkAgg
ORIGINAL_XDG_CURRENT_DESKTOP
                       undefined
PAGER                  /usr/bin/less
PATH                   /opt/local/bin:/opt/local/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/share/dotnet:/opt/X11/bin:~/.dotnet/tools:/Library/Apple/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Users/adamelder/Applications/quarto/bin:/usr/texbin:/Applications/RStudio.app/Contents/Resources/app/quarto/bin:/Applications/RStudio.app/Contents/Resources/app/bin/postback
PYTHONIOENCODING       utf-8
R_ARCH                 
R_BROWSER              /usr/bin/open
R_BZIPCMD              /usr/bin/bzip2
R_CLI_HAS_HYPERLINK_IDE_HELP
                       true
R_CLI_HAS_HYPERLINK_IDE_RUN
                       true
R_CLI_HAS_HYPERLINK_IDE_VIGNETTE
                       true
R_DOC_DIR              /usr/local/Cellar/r/4.3.1/lib/R/doc
R_GZIPCMD              /usr/bin/gzip
R_HOME                 /usr/local/Cellar/r/4.3.1/lib/R
R_INCLUDE_DIR          /usr/local/Cellar/r/4.3.1/lib/R/include
R_LIBS_SITE            /usr/local/Cellar/r/4.3.1/lib/R/site-library
R_LIBS_USER            /Users/adamelder/Library/R/x86_64/4.3/library
R_PAPERSIZE            a4
R_PDFVIEWER            /usr/bin/open
R_PLATFORM             x86_64-apple-darwin22.4.0
R_PRINTCMD             lpr
R_RD4PDF               times,inconsolata,hyper
R_RUNTIME              
R_SESSION_TMPDIR       /var/folders/c0/_98bzxtd0yn7x95q6vbqmfjm0000gn/T//Rtmp3h9uQC
R_SHARE_DIR            /usr/local/Cellar/r/4.3.1/lib/R/share
R_STRIP_SHARED_LIB     strip -x
R_STRIP_STATIC_LIB     strip -S
R_SYSTEM_ABI           macos,gcc,gxx,gfortran,gfortran
R_TEXI2DVICMD          texi2dvi
R_UNZIPCMD             /usr/bin/unzip
R_ZIPCMD               /usr/bin/zip
RMARKDOWN_MATHJAX_PATH
                       /Applications/RStudio.app/Contents/Resources/app/resources/mathjax-27
RS_LOG_LEVEL           WARN
RS_RPOSTBACK_PATH      /Applications/RStudio.app/Contents/Resources/app/bin/rpostback
RS_SHARED_SECRET       f8fb2f76-1a8c-4297-8389-4eac20f6e811
RSTUDIO                1
RSTUDIO_CLI_HYPERLINKS
                       true
RSTUDIO_CONSOLE_COLOR
                       256
RSTUDIO_CONSOLE_WIDTH
                       78
RSTUDIO_FALLBACK_LIBRARY_PATH
                       /var/folders/c0/_98bzxtd0yn7x95q6vbqmfjm0000gn/T/rstudio-fallback-library-path-905219330
RSTUDIO_PANDOC         /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools
RSTUDIO_PROGRAM_MODE   desktop
RSTUDIO_SESSION_PID    11666
RSTUDIO_SESSION_PORT   23379
RSTUDIO_USER_IDENTITY
                       adamelder
RSTUDIO_WINUTILS       bin/winutils
SED                    /usr/bin/sed
SHELL                  /bin/zsh
SSH_ASKPASS            rpostback-askpass
SSH_AUTH_SOCK          /private/tmp/com.apple.launchd.mSU238J977/Listeners
TAR                    /usr/bin/tar
TERM                   xterm-256color
TMPDIR                 /var/folders/c0/_98bzxtd0yn7x95q6vbqmfjm0000gn/T/
TWITTER_PAT            /Users/adamelder/.rtweet_token1.rds
USER                   adamelder
XPC_FLAGS              0x0
XPC_SERVICE_NAME       application.com.rstudio.desktop.46622767.52115142

Thanks for any assistance!

nloptr can be quite picky when it comes to cmake - Which version of cmake do you have in /usr/local/bin (cmake --version) ? On my Mac I have cmake 3.23.3 and this works quite well allowing be to build nloptr 2.0.3 successfully from sources.

"Only" reason for nloptr to actually need cmake is if it cannot find any installation of nlopt on your system - in such a case nloptr needs to not only build the R package but also build the nloptsoftware that nloptr provides an interface for.

Another avenue that you could take in order to solve your issue is to use R package binaries.

install.packages("nloptr",repos="https://cran.rstudio.com/",type="binary" )

should automatically install R package binaries and hence circumventing the cmake issue to start with.

(Cross-linking an earlier issue about nloptr for awareness Installing package nloptr)

Thanks for this. I am assuming you are correct. I will post again when I have time to attempt this!