Rstan incosistently running

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

The cl <- parallel::makeCluster(2, setup_strategy = "sequential") didn’t error for me and my rprofile file did already have this code from torkar. I will post on the r studio forum to see if there is another step I am missing. Or if I will be unable to run Stan from my computer.

In the other post you just posted you still have the same problem with something pointing to clang7. You should get rid of that :) It’s hard for us to do it. I don’t know where this is set on your computer, but clang7 on OS X and R v4.0.0 is a no-go.

Thank you!!!

I ran this code: ```
sudo rm -rf /usr/local/clang{4,6,7}


and my RStan worked!
From:
https://thecoatlessprofessor.com/programming/r/uninstalling-the-r-development-toolchain-on-macos/
1 Like

Hi

There is a space in your path (I’m reading this on a phone now but it says “texbin name”. I’m not sure that ok?

R