Rstan incosistently running

Somehow your PATH environmental variable is such that it is putting /usr/local/clang7/bin in front of /usr/bin . In other words, that should say /usr/bin/clang++ in order to use Xcode’s clang++. But that is commented out of your ~/.Renviron file, so it has to be from somewhere else that I don’t know.

Would the solution be to uninstall everything and reinstall then?

No. Nothing with C++ code will install from source with that PATH. The solution is to find what is setting the PATH like that and undo it.

Thank you for your help! I’m not familiar with how to correct the path but now that I now this is the source of errors I can look up ways to correct it.

If you go into the Terminal tab of RStudio and execute

echo ${PATH}

what does it say?

echo {PATH} Error: unexpected '{' in "echo {"

Maybe just

echo $PATH

Error: object ‘echo’ not found

in the terminal this runs:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/clang7/bin

OK. Whatever adds or added :/usr/local/clang7/bin onto the end needs to not do that.

Thank you! Is this something I can open and edit directly?

In any shell session you can just do

export PATH = /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin

or in R you can do

Sys.setenv(PATH = "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin")

but it won’t persist across sessions unless you change the PATH permanently. There is probably some iPATH app that will do so on a Mac.

After running the R code sys.setenv then rerunning my stan code, there was this error:

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! In file included from :1:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/Eigen/Dense:1:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/Eigen/Core:82:
In file included from /usr/local/clang7/include/c++/v1/new:91:
In file included from /usr/local/clang7/include/c++/v1/exception:82:
In file included from /usr/local/clang7/include/c++/v1/cstdlib:86:
/usr/local/clang7/include/c++/v1/stdlib.h:94:15: fatal error: ‘stdlib.h’ file not found
#include_next <stdlib.h>
^~~~~~~~~~
1 error generated.
make: *** [file493485a1e06.o] Error 1
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file493485a1e06.cpp 2> file493485a1e06.cpp.err.txt’ had status 1
Error in sink(type = “output”) : invalid connection

That is the same problem: It should not be looking under /usr/local/clang7 .

When I use your code to change the PATH, this is success when I check it Sys.getenv(). When I check after running rstan code, Sys.getenv() still shows the PATH without the end /usr/local/clang7/bin

It seems the error still occurs when R has the corrected PATH?

It may be that the R subprocess that gets spawned picks up the path with /usr/local/clang7/bin.

That means it will be impossible to fix in rstudio on this computer?

Perhaps impossible inside RStudio but not impossible to fix in general.

Thank you so much! The error message misled me to think Rstudio couldn’t locate the file stdlib.h so I would never have know about the PATH as the soruce.

For trouble shooting and correcting the path so I am able to run RStan I would need to contact Apple for this or a general computer OS help forum?

When I created an a new user profile on my computer and installed R, RStudio, and Stan there was a different error message:

fit ← stan(file = ‘schools.stan’,

  •         data = schools_dat)
    

starting worker pid=1863 on localhost:11832 at 15:16:49.630
starting worker pid=1865 on localhost:11832 at 15:16:49.638
starting worker pid=1862 on localhost:11832 at 15:16:49.638
starting worker pid=1864 on localhost:11832 at 15:16:49.642
Error in unserialize(node$con) : error reading from connection
Calls: → slaveLoop → makeSOCKmaster
Error in unserialize(node$con) : error reading from connection
Calls: → slaveLoop → makeSOCKmaster
Error in unserialize(node$con) : error reading from connection
Calls: → slaveLoop → makeSOCKmaster
Execution halted
Execution halted
Execution halted
Error in unserialize(node$con) : error reading from connection
Calls: → slaveLoop → makeSOCKmaster
Execution halted
Error in makePSOCKcluster(names = spec, …) :
Cluster setup failed. 4 of 4 workers failed to connect.

That is a RStudio bug