Can get Stan to execute commands after new installation R version 4.0 Mojave Mac

After carefully following (and re-following) the instruction to install Rstan, I can’t get anything to run. Rstan itself appears to install fine, but every command I try to execute bombs.

I’m using Rstudio 1.2.5042, R 4.0 on an iMac OS 10.14.6.

I followed this for Mac: GitHub - coatless-mac/r-macos-rtools: Scripts to build an **unofficial** Rtools-esq installer for the macOS R toolchain
Later, I installed Xcode to try to address the issue.
Later, when this failed, I used supo commands to try to set the path directly, following this: RStan Mojave Mac OS X Prerequisite Installation Instructions · stan-dev/rstan Wiki · GitHub

Here's one of my many tries at running Stan. Here, using the Rethinking command ulam

m9.1 <- ulam(
+   alist(
+     log_gdp_std ~ dnorm( mu , sigma ) ,
+     mu <- a[cid] + b[cid]*( rugged_std - 0.215 ) ,
+     a[cid] ~ dnorm( 1 , 0.1 ) ,
+     b[cid] ~ dnorm( 0 , 0.3 ) ,
+     sigma ~ dexp( 1 )
+   ) , data=dat_slim , chains=1 )

Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! In file included from <built-in>: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:535:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:10:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
In file included from <built-in>: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.
In addition: Warning message:
In system(cmd, intern = !verbose) :
  running command '/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file11f15c3d7370.cpp 2> file11f15c3d7370.cpp.err.txt' had status 1
Error in sink(type = "output") : invalid connection

If your question relates to installation please provide the following information:

Here are these:

  • Output of writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))
  • Output of devtools::session_info("rstan")

devtools::session_info(“rstan”)
─ Session info ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
setting value
version R version 4.0.0 (2020-04-24)
os macOS Mojave 10.14.6
system x86_64, darwin17.0
ui RStudio
language (EN)
collate en_US.UTF-8
ctype en_US.UTF-8
tz America/New_York
date 2020-04-30

─ Packages ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
package * version date lib source
assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.0)
backports 1.1.6 2020-04-05 [1] CRAN (R 4.0.0)
BH 1.72.0-3 2020-01-08 [1] CRAN (R 4.0.0)
callr 3.4.3 2020-03-28 [1] CRAN (R 4.0.0)
checkmate 2.0.0 2020-02-06 [1] CRAN (R 4.0.0)
cli 2.0.2 2020-02-28 [1] CRAN (R 4.0.0)
colorspace 1.4-1 2019-03-18 [1] CRAN (R 4.0.0)
crayon 1.3.4 2017-09-16 [1] CRAN (R 4.0.0)
desc 1.2.0 2018-05-01 [1] CRAN (R 4.0.0)
digest 0.6.25 2020-02-23 [1] CRAN (R 4.0.0)
ellipsis 0.3.0 2019-09-20 [1] CRAN (R 4.0.0)
evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.0)
fansi 0.4.1 2020-01-08 [1] CRAN (R 4.0.0)
farver 2.0.3 2020-01-16 [1] CRAN (R 4.0.0)
ggplot2 3.3.0 2020-03-05 [1] CRAN (R 4.0.0)
glue 1.4.0 2020-04-03 [1] CRAN (R 4.0.0)
gridExtra 2.3 2017-09-09 [1] CRAN (R 4.0.0)
gtable 0.3.0 2019-03-25 [1] CRAN (R 4.0.0)
inline 0.3.15 2018-05-18 [1] CRAN (R 4.0.0)
isoband 0.2.1 2020-04-12 [1] CRAN (R 4.0.0)
labeling 0.3 2014-08-23 [1] CRAN (R 4.0.0)
lattice 0.20-41 2020-04-02 [1] CRAN (R 4.0.0)
lifecycle 0.2.0 2020-03-06 [1] CRAN (R 4.0.0)
loo 2.2.0 2019-12-19 [1] CRAN (R 4.0.0)
magrittr 1.5 2014-11-22 [1] CRAN (R 4.0.0)
MASS 7.3-51.5 2019-12-20 [1] CRAN (R 4.0.0)
Matrix 1.2-18 2019-11-27 [1] CRAN (R 4.0.0)
matrixStats 0.56.0 2020-03-13 [1] CRAN (R 4.0.0)
mgcv 1.8-31 2019-11-09 [1] CRAN (R 4.0.0)
munsell 0.5.0 2018-06-12 [1] CRAN (R 4.0.0)
nlme 3.1-147 2020-04-13 [1] CRAN (R 4.0.0)
pillar 1.4.3 2019-12-20 [1] CRAN (R 4.0.0)
pkgbuild 1.0.7 2020-04-25 [1] CRAN (R 4.0.0)
pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.0)
pkgload 1.0.2 2018-10-29 [1] CRAN (R 4.0.0)
praise 1.0.0 2015-08-11 [1] CRAN (R 4.0.0)
prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.0.0)
processx 3.4.2 2020-02-09 [1] CRAN (R 4.0.0)
ps 1.3.2 2020-02-13 [1] CRAN (R 4.0.0)
R6 2.4.1 2019-11-12 [1] CRAN (R 4.0.0)
RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 4.0.0)
Rcpp 1.0.4.6 2020-04-09 [1] CRAN (R 4.0.0)
RcppEigen 0.3.3.7.0 2019-11-16 [1] CRAN (R 4.0.0)
rlang 0.4.5 2020-03-01 [1] CRAN (R 4.0.0)
rprojroot 1.3-2 2018-01-03 [1] CRAN (R 4.0.0)
rstan 2.19.3 2020-02-11 [1] CRAN (R 4.0.0)
rstudioapi 0.11 2020-02-07 [1] CRAN (R 4.0.0)
scales 1.1.0 2019-11-18 [1] CRAN (R 4.0.0)
StanHeaders 2.19.2 2020-02-11 [1] CRAN (R 4.0.0)
testthat 2.3.2 2020-03-02 [1] CRAN (R 4.0.0)
tibble 3.0.1 2020-04-20 [1] CRAN (R 4.0.0)
utf8 1.1.4 2018-05-24 [1] CRAN (R 4.0.0)
vctrs 0.2.4 2020-03-10 [1] CRAN (R 4.0.0)
viridisLite 0.3.0 2018-02-01 [1] CRAN (R 4.0.0)
withr 2.2.0 2020-04-20 [1] CRAN (R 4.0.0)

writeLines(readLines(file.path(Sys.getenv(“HOME”), “.R/Makevars”)))

clang: start

CFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CCFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CXXFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CPPFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include

SHLIB_CXXLDFLAGS+=-Wl,-rpath,{R_HOME}/lib {R_HOME}/lib/libc++abi.1.dylib
SHLIB_CXX14LDFLAGS+=-Wl,-rpath,{R_HOME}/lib {R_HOME}/lib/libc++abi.1.dylib

clang: end

CPPFLAGS=“-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include”

devtools::session_info(“rstan”)
─ Session info ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
setting value
version R version 4.0.0 (2020-04-24)
os macOS Mojave 10.14.6
system x86_64, darwin17.0
ui RStudio
language (EN)
collate en_US.UTF-8
ctype en_US.UTF-8
tz America/New_York
date 2020-04-30

─ Packages ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
package * version date lib source
assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.0)
backports 1.1.6 2020-04-05 [1] CRAN (R 4.0.0)
BH 1.72.0-3 2020-01-08 [1] CRAN (R 4.0.0)
callr 3.4.3 2020-03-28 [1] CRAN (R 4.0.0)
checkmate 2.0.0 2020-02-06 [1] CRAN (R 4.0.0)
cli 2.0.2 2020-02-28 [1] CRAN (R 4.0.0)
colorspace 1.4-1 2019-03-18 [1] CRAN (R 4.0.0)
crayon 1.3.4 2017-09-16 [1] CRAN (R 4.0.0)
desc 1.2.0 2018-05-01 [1] CRAN (R 4.0.0)
digest 0.6.25 2020-02-23 [1] CRAN (R 4.0.0)
ellipsis 0.3.0 2019-09-20 [1] CRAN (R 4.0.0)
evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.0)
fansi 0.4.1 2020-01-08 [1] CRAN (R 4.0.0)
farver 2.0.3 2020-01-16 [1] CRAN (R 4.0.0)
ggplot2 3.3.0 2020-03-05 [1] CRAN (R 4.0.0)
glue 1.4.0 2020-04-03 [1] CRAN (R 4.0.0)
gridExtra 2.3 2017-09-09 [1] CRAN (R 4.0.0)
gtable 0.3.0 2019-03-25 [1] CRAN (R 4.0.0)
inline 0.3.15 2018-05-18 [1] CRAN (R 4.0.0)
isoband 0.2.1 2020-04-12 [1] CRAN (R 4.0.0)
labeling 0.3 2014-08-23 [1] CRAN (R 4.0.0)
lattice 0.20-41 2020-04-02 [1] CRAN (R 4.0.0)
lifecycle 0.2.0 2020-03-06 [1] CRAN (R 4.0.0)
loo 2.2.0 2019-12-19 [1] CRAN (R 4.0.0)
magrittr 1.5 2014-11-22 [1] CRAN (R 4.0.0)
MASS 7.3-51.5 2019-12-20 [1] CRAN (R 4.0.0)
Matrix 1.2-18 2019-11-27 [1] CRAN (R 4.0.0)
matrixStats 0.56.0 2020-03-13 [1] CRAN (R 4.0.0)
mgcv 1.8-31 2019-11-09 [1] CRAN (R 4.0.0)
munsell 0.5.0 2018-06-12 [1] CRAN (R 4.0.0)
nlme 3.1-147 2020-04-13 [1] CRAN (R 4.0.0)
pillar 1.4.3 2019-12-20 [1] CRAN (R 4.0.0)
pkgbuild 1.0.7 2020-04-25 [1] CRAN (R 4.0.0)
pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.0)
pkgload 1.0.2 2018-10-29 [1] CRAN (R 4.0.0)
praise 1.0.0 2015-08-11 [1] CRAN (R 4.0.0)
prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.0.0)
processx 3.4.2 2020-02-09 [1] CRAN (R 4.0.0)
ps 1.3.2 2020-02-13 [1] CRAN (R 4.0.0)
R6 2.4.1 2019-11-12 [1] CRAN (R 4.0.0)
RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 4.0.0)
Rcpp 1.0.4.6 2020-04-09 [1] CRAN (R 4.0.0)
RcppEigen 0.3.3.7.0 2019-11-16 [1] CRAN (R 4.0.0)
rlang 0.4.5 2020-03-01 [1] CRAN (R 4.0.0)
rprojroot 1.3-2 2018-01-03 [1] CRAN (R 4.0.0)
rstan 2.19.3 2020-02-11 [1] CRAN (R 4.0.0)
rstudioapi 0.11 2020-02-07 [1] CRAN (R 4.0.0)
scales 1.1.0 2019-11-18 [1] CRAN (R 4.0.0)
StanHeaders 2.19.2 2020-02-11 [1] CRAN (R 4.0.0)
testthat 2.3.2 2020-03-02 [1] CRAN (R 4.0.0)
tibble 3.0.1 2020-04-20 [1] CRAN (R 4.0.0)
utf8 1.1.4 2018-05-24 [1] CRAN (R 4.0.0)
vctrs 0.2.4 2020-03-10 [1] CRAN (R 4.0.0)
viridisLite 0.3.0 2018-02-01 [1] CRAN (R 4.0.0)
withr 2.2.0 2020-04-20 [1] CRAN (R 4.0.0)

If you are reporting a bug (thank you!) please use the issue tracker (Issues · stan-dev/rstan · GitHub) instead of the forums.

Looking forward to your topic!

What is Sys.getenv("PATH")?

Sorry, thought I had included that:

writeLines(readLines(file.path(Sys.getenv(“HOME”), “.R/Makevars”)))

clang: start

CFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CCFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CXXFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CPPFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include

SHLIB_CXXLDFLAGS+=-Wl,-rpath,{R_HOME}/lib {R_HOME}/lib/libc++abi.1.dylib
SHLIB_CXX14LDFLAGS+=-Wl,-rpath,{R_HOME}/lib {R_HOME}/lib/libc++abi.1.dylib

clang: end

In the process of trying to fix this, I’ve tried re-install the rcpp package. It bombs and won’t re-install. But, I can still ‘library’ it This led me to consider executing the approach at this link, but I’ve not done that yet. https://thecoatlessprofessor.com/programming/cpp/r-compiler-tools-for-rcpp-on-macos/

That is writeLines(readLines(file.path(Sys.getenv(“HOME”), “.R/Makevars”))), but we need Sys.getenv("PATH").

Sys.getenv(“PATH”)
[1] “/usr/local/clang7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Library/TeX/texbin”

You do not need the macos-rtools anymore, for R 4.0.
I encountered this error in my OSX testing as well.

Rename (or delete) ~/.Renviron and ~/.R/Makevars

That will ‘undo’ the configuration of macos-rtools.
Then test rstan in a new R session.

Well, thanks Stephen. At least, I’m now getting a different error (maybe that’s progress). See below (I only get the “recompiling to avoid crashing” error sometimes):

m9.1c <- ulam(

  • alist(
  • log_gdp_std ~ dnorm( mu , sigma ) ,
    
  • mu <- a[cid] + b[cid]*( rugged_std - 0.215 ) ,
    
  • a[cid] ~ dnorm( 1 , 0.1 ) ,
    
  • b[cid] ~ dnorm( 0 , 0.3 ) ,
    
  • sigma ~ dexp( 1 )
    
  • ) ,
  • data=dat_slim , chains=4 , cores=4 , iter=1000 )
    recompiling to avoid crashing R session
    starting worker pid=47488 on localhost:11118 at 20:37:22.965
    starting worker pid=47486 on localhost:11118 at 20:37:22.965
    starting worker pid=47485 on localhost:11118 at 20:37:22.964
    starting worker pid=47487 on localhost:11118 at 20:37:22.965
    Error in unserialize(node$con) : error reading from connection
    Calls: -> slaveLoop -> makeSOCKmaster
    Execution halted
    Error in unserialize(node$con) : error reading from connection
    Calls: -> slaveLoop -> makeSOCKmaster
    Execution halted
    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
    Error in makePSOCKcluster(names = spec, …) :
    Cluster setup failed. 4 of 4 workers failed to connect.

That is a known problem with known workarounds