I am having trouble getting RStan to work on Mac OS Sierra and, after many attempts, google searches and double-checking against my well working RStan on a (different) Windows machine, I think the problem lies with C++.
The OS Sierra version is 10.12.6
Xcode version 8.3.3 (when installing it I opened it once and accepted the license agreement)
R version 3.4.1
RStan version 2.16.2 (seems to me to be well installed)
After following the instructions there, my Makevars file currently looks like this (it seems that this is what solved the problem reported in that conversation): CXXFLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function -Wno-macro-redefined
But when I try to run a stan() model I get the following error message:
Error in if (nchar(CXX) == 0) { : argument is of length zero In addition: Warning messages: 1: In readLines(file, warn = TRUE) :
** incomplete final line found on ‘/Users/userInvite2/Documents/Evangelia/glmm_model.stan’** 2: running command ‘’/Library/Frameworks/R.framework/Resources/bin/R’ CMD config CXX 2>/dev/null’ had status 1
When I type in rstan:::get_CXX() I get the following output: character(0) attr(,“status”) [1] 1 Warning message: running command ‘’/Library/Frameworks/R.framework/Resources/bin/R’ CMD config CXX 2>/dev/null’ had status 1
That looks like xcode did not install properly or R can’t find xcode. Can
you manually at the terminal see if xcrun is there (or just search for it
globally with spotlight to see if it’s at a different path?)
Xcode is either not fully installed or at a different path. If you
searched globally (either spotlight or locate) and found nothing for xcrun
I would try the solutions at this link and the “missing tools” link
therein:
I had a mac for a while for Stan development and it worked great so my
guess is maybe there are more steps to the xcode install than there used to
be or something minor like that. I used to install everything through brew
and I recall the one problem initially was getting paths in place correctly.
Super, you want the minimal one, so the easiest way to check is to compile a model without a Makevars but with the verbose flag. Check that the call to the compiler (clang++ I think) has a -O3 flag for the model compilation. I think the mtune native flag is fine (it should be the default anyway) as long as it’s not causing models to crash. The other flags should be unnecessary, though they might hide irrelevant warnings.
@bgoodri should be able to say what the official recommendation is.
I’m not sure this is what you meant, but when I ran the model, at the beginning it said the following:
In file included from file3e07cdbc2b1.cpp:8:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/src/stan/model/model_header.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math/rev/mat.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math/rev/core.hpp:12:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math/rev/core/gevv_vvv_vari.hpp:5:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math/rev/core/var.hpp:7:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/BH/include/boost/math/tools/config.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/BH/include/boost/config.hpp:39:
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/BH/include/boost/config/compiler/clang.hpp:200:11: warning: ‘BOOST_NO_CXX11_RVALUE_REFERENCES’ macro redefined [-Wmacro-redefined] #define BOOST_NO_CXX11_RVALUE_REFERENCES
^
:6:9: note: previous definition is here #define BOOST_NO_CXX11_RVALUE_REFERENCES 1
^
1 warning generated.
Then the model ran normally until the end.
The chains (4, 3000 iterations each) look good, as well as the Rhat, so everything seems fine. Plus the results seem reasonable.
But I didn’t find the line you were expecting (clang++ … … -03 … ).
Can I rely on this model or should I change / modify anything else in terms of compiler etc.?
The model is fine, it looks like rstan doesn’t print the line I was looking for out and I don’t recall right now how to get it. If you don’t have a Makevars it’s possible the -O3 flag will not make it into your compilation flags and your model will run slower than it needs to. I’d just try it with the makevars as recommended in the rstan install instructions now that you have xcode in place.