Error / bug in brms models?

I accepted Xcode, loaded the new version, and restarted R.

> library(rstan)
> example(stan_model, run.dontrun = TRUE)

stn_md> stancode <- 'data {real y_mean;} parameters {real y;} model {y ~ normal(y_mean,1);}'

stn_md> mod <- stan_model(model_code = stancode)
Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! In file included from file4f39414ad5fc.cpp:8:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/src/stan/model/model_header.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math/rev/mat.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math/rev/core.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math/rev/core/autodiffstackstorage.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math/memory/stack_alloc.hpp:8:
In file included from /usr/local/clang4/bin/../include/c++/v1/cstdlib:86:
In addition: Warning message:
In system(cmd, intern = !verbose) :
  running command '/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file4f39414ad5fc.cpp 2> file4f39414ad5fc.cpp.err.txt' had status 1
Error in sink(type = "output") : invalid connection

Try again after doing

file.rename("~/.R/Makevars", "~/R/old_Makevars")

@jonnations

Xcode, the command line tools, than i tried this :https://github.com/rmacoslib/r-macos-rtools
but that didnt work so i installed gofortran and clang myself and than checked if r whas able to give c++ compiling comand by a lillte test:

pkgbuild::has_build_tools(debug = TRUE)

if the test works, BRMS works

Ok, that worked! I tried it on a few brms models that weren’t working, and everything seems fine with them too.

Excellent, thank you so much @bgoodri for all the help! As you can probably tell I’m a user not a developer. And thanks to the others that chimed in.

Hi,

I’m still having this problem with running STAN. When I try the code:

file.rename(“~/.R/Makevars”, “~/R/old_Makevars”)

I get the result:

cannot rename file ‘/Users/pedro/.R/Makevars’ to ‘/Users/pedro/.R/old_Makevars’, reason ‘Permission denied’

You may have to rename that file from outside R. I can’t imagine why you don’t have permissions to create files in your own home directory though.

Thanks bgoodri! I made Mac show the hidden files and renamed the file but when I try to run:

example(stan_model, run.dontrun = TRUE)

Or any other Stan models, I still get:

Error in if (nchar(CXX) == 0) { : argument is of length zero
In addition: Warning message:
In system2(file.path(R.home(component = “bin”), “R”), args = paste(“CMD config”, :
running command ‘’/Library/Frameworks/R.framework/Resources/bin/R’ CMD config CXX14 2>/dev/null’ had status 69

Any ideas on how to solve this? I’m a beginner user (and I was able to use R Stan in my computer before)

I think I’m having similar problems to here and am struggling to solve it after trying quite a few things!

I uninstalled R and Rstudio, and re-installed R and Rstudio following the instructions: https://cran.r-project.org/

Trying to install the rethinking package, and was following the instructions from McElreath himself and r stan from Software | Richard McElreath and RStan Getting Started · stan-dev/rstan Wiki · GitHub

R version 3.6.1, RStudio version 1.2.1335m OS is macOS Mojave 10.14.5
stan_version() returns 2.19.1

If I run library(rstan) and then model <- stan_demo() and pick the first model from the demo, I get an error of

In file included from /usr/local/include/stdint.h:59:
In file included from
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file38c18d8a8d0.cpp 2> file38c18d8a8d0.cpp.err.txt’ had status 1
Error in sink(type = “output”) : invalid connection

I have run sudo xcode-select --reset, sudo xcode-select --install and sudo xcodebuild -license accept, and also opened up xcode GUI. Same error.

Also tried downloading and running
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /. Same error

I have tried installing clang7.0.0 and gfortran6.1 from R for macOS - Development Tools and Libraries
Same error

I have looked for my stdint.h and have 9 of them!
One in /usr/include, one in /usr/local/include, one in ‎⁨Macintosh HD⁩ ▸ ⁨System⁩ ▸ ⁨Library⁩ ▸ ⁨Frameworks⁩ ▸ ⁨Kernel.framework⁩ ▸ ⁨Versions⁩ ▸ ⁨A⁩ ▸ ⁨Headers⁩
One in ‎⁨Macintosh HD⁩ ▸ ⁨Library⁩ ▸ ⁨Developer⁩ ▸ ⁨CommandLineTools⁩ ▸ ⁨SDKs⁩ ▸ ⁨MacOSX.sdk⁩ ▸ ⁨System⁩ ▸ ⁨Library⁩ ▸ ⁨Frameworks⁩ ▸ ⁨Kernel.framework⁩ ▸ ⁨Versions⁩ ▸ ⁨A⁩ ▸ ⁨Headers⁩
and five in /anaconda3/pkgs/libcxx... (with various version numbers)

Modified Makevars to look like:
CXX14FLAGS += -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include CXX14FLAGS += -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include CXX11FLAGS += -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include CXXFLAGS += -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include CXX11FLAGS += -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include CXXFLAGS += -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include

And also tried moving Makevars so that it’s renamed Makevars_old

Also tried running Sys.setenv(USE_CXX14=1) after library(rstan)

Still the same error.
I get an error when trying to download and install Rtools from GitHub - coatless-mac/r-macos-rtools: Scripts to build an **unofficial** Rtools-esq installer for the macOS R toolchain

pkgbuild::has_build_tools(debug = TRUE) returns TRUE

Any suggestions?

P.S. Sorry for wall of text and replying to a 7 month old topic.

1 Like

Hi Alex,

I am facing the same problem now. Did you fix it?

These configuration things have little to do with brms. What is the output of

library(rstan)
example(stan_model, run.dontrun = TRUE)

particularly the part that says error: (with the colon)?

Thank god you responded!

I have got till here,

pkgbuild::has_build_tools(debug = TRUE) #successfully installed the Rtools
[1] TRUE

This is my Makevars file at present,
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
CXX14FLAGS = -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include

SHLIB_CXXLDFLAGS+=-Wl,-rpath,/Library/Frameworks/R.framework/Resources/lib /Library/Frameworks/R.framework/Resources/lib/libc++abi.1.dylib
SHLIB_CXX11LDFLAGS+=-Wl,-rpath,/Library/Frameworks/R.framework/Resources/lib /Library/Frameworks/R.framework/Resources/lib/libc++abi.1.dylib
SHLIB_CXX14LDFLAGS+=-Wl,-rpath,/Library/Frameworks/R.framework/Resources/lib /Library/Frameworks/R.framework/Resources/lib/libc++abi.1.dylib

clang: end

CXX14FLAGS=-O3 -march=native -mtune=native
CXX14FLAGS += -arch x86_64 -ftemplate-depth-256

Output for your request is as follows,

library(rstan)
example(stan_model, run.dontrun = TRUE)

stn_md> stancode ← ‘data {real y_mean;} parameters {real y;} model {y ~ normal(y_mean,1);}’

stn_md> mod ← stan_model(model_code = stancode, verbose = TRUE)

TRANSLATING MODEL ‘16a540c6086086816528e4524def24d9’ FROM Stan CODE TO C++ CODE NOW.
successful in parsing the Stan model ‘16a540c6086086816528e4524def24d9’.
COMPILING THE C++ CODE FOR MODEL ‘16a540c6086086816528e4524def24d9’ NOW.
OS: x86_64, darwin15.6.0; rstan: 2.19.3; Rcpp: 1.0.3; inline: 0.3.15

setting environment variables:
PKG_LIBS = -L’/Users/mano/Library/R/3.5/library/StanHeaders/lib/’ -lStanHeaders
PKG_CPPFLAGS = -I"/Users/mano/Library/R/3.5/library/Rcpp/include/" -I"/L
.
.
.

357: return Rcpp::wrap(“16a540c6086086816528e4524def24d9”);
358: }
359:
360:
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 /Users/mano/Library/R/3.5/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Dense:1:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Core:531:
/Library/Frameworks/R.framework/Versions/3.5/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 :1:
In file included from /Users/mano/Library/R/3.5/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Dense:2:
In

I have deleted a lot of lines in between. It ends at this point.

The lines in between had the part about error: buried in them.

I found this one,

clang-7: error: no such file or directory: ‘/Library/Frameworks/R.framework/Resources/lib/libc++abi.1.dylib’

Did you run the installer from

https://github.com/rmacoslib/r-macos-rtools/releases/download/v3.2.2/macos-rtools-3.2.2.pkg

by pressing Ctrl when you click on it to get the menu with the Open option?

Or maybe what version of R are you using?

Yes. I installed using ctrl and selecting open as instructed in the manual.

I have uploaded a screenshot of the installer window.

I just updated the Rstudio to recent version yesterday while installing Stan.

R version info,

platform x86_64-apple-darwin15.6.0
arch x86_64
os darwin15.6.0
system x86_64, darwin15.6.0
status
major 3
minor 5.1
year 2018
month 07
day 02
svn rev 74947
language R
version.string R version 3.5.1 (2018-07-02)
nickname Feather Spray

I think you will be fine if you update R to 3.6.x .

I have updated my R version now and still getting the following error when I run the model,

Blockquote

schools_dat ← list(J = 8,

  •                 y = c(28,  8, -3,  7, -1,  1, 18, 12),
    
  •                 sigma = c(15, 10, 16, 11,  9, 11, 10, 18))
    

setwd(“~/Documents/WHOI_2/Stan”)
fit ← stan(file = ‘8schools.stan’, data = schools_dat)
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/3.6/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/RcppEigen/include/Eigen/Dense:1:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/RcppEigen/include/Eigen/Core:535:
/Library/Frameworks/R.framework/Versions/3.6/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 :1:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file3e16741bb6ae.cpp 2> file3e16741bb6ae.cpp.err.txt’ had status 1
Error in sink(type = “output”) : invalid connection

Blockquote

version
_
platform x86_64-apple-darwin15.6.0
arch x86_64
os darwin15.6.0
system x86_64, darwin15.6.0
status
major 3
minor 6.2
year 2019
month 12
day 12
svn rev 77560
language R
version.string R version 3.6.2 (2019-12-12)
nickname Dark and Stormy Night

Need to see the output of

library(rstan)
example(stan_model, run.dontrun = TRUE)

again with the R 3.6.x.