Compiling Stan program... block

Hello,
I’m trying to run a brm model using Stan. After I run the brm model it says “Compiling Stan program…” and nothing happens. So when I run “summary(model1)” it says “object ‘model1’ not found”. I left the code running for hours for a couple of days now but still nothing. Would really appreciate some help here :) Thanks!

Here is the code from the start:

## load necessary packages
library(brms)
library(bayesplot)
library(rstanarm)
library(rstan)
library(tidyverse)

# load datasets
load('data.RData')

##### Model 1: 

# Set priors
m1priors <- c(prior(student_t(3, 0, 2.5), class = "Intercept"), prior(student_t(3, 0, 2.5), class = "b"))


# Bayesian analysis using brms
model1 = brm(
  data = test.data.model1,
  total.interventions ~ 1 +
    z.rank.higher +
    z.rank.lower +
    z.dsi.groomer1.groomer2 +
    kin.groomers +
    z.bystanders +
    (1 + z.rank.lower + z.dsi.groomer1.groomer2 + kin.groomers||higher) +
    (1 + z.rank.higher + z.dsi.groomer1.groomer2 + kin.groomers||lower) +
    offset(log(duration)),
  prior = m1priors,
  warmup = 500,
  iter = 3000,
  cores = 10,
  chains = 2,
  family = bernoulli(link = 'logit'),
  seed = 123
)

I’m using macOS Catalina version 10.15.6
brms version: 2.13.5
R version: 3.6.0

And the rstan version that doesn’t compile is 2.21.2.

Hi Atsev,

The first thing to check here is your RStan installation. Can you run:

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

And post any lines that start with error:?

Hello andrjohns,
Thanks for your reply.

When I run the code it opens a window saying that to install R packages from source requires additional tools and brings me to this website https://www.cnet.com/how-to/install-command-line-developer-tools-in-os-x/
But I already have Xcode on my mac.

This is the error:

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! clang: warning: no such sysroot directory: ‘/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk’ [-Wmissing-sysroot]
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:82:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/…/include/c++/v1/new:90:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/…/include/c++/v1/exception:81:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/…/include/c++/v1/cs
In addition: Warning message:
In find.package(package, lib.loc, verbose = verbose) :
package ‘base’ found more than once, using the first from
“/Library/Frameworks/R.framework/Resources/library/base”,
“/Library/Frameworks/R.framework/Versions/3.6/Resources/library/base”

I don’t know if I should update my R version to 4.0.1 or if it will mess up things worse

Thank you for the help

sorry to R version 4.0.2 because my friend tried to run the same code on this version and it works

That looks like your c++ toolchain isn’t set up quite right. I’m not on Mac so I can’t help troubleshoot much more, but @jonah should be able to help here (or know who else to tag).

Jonah, this user is on Catalina with R 3.6.0 and is having compilation errors related to the toolchain not being found. What’s next for troubleshooting here?

2 Likes

Unfortunately it’s pretty hard right now to get it working with R 3.6 on Mac. It seems to require installing a bunch of packages from source (probably at least Rcpp, StanHeaders, RStan) and I’m not even sure what Makevars settings are required. @bgoodri do you know?

By far the easiest solution is to install the latest version of R (probably a good idea anyway) and use the following lines in the Makevars file:

# use file.edit(file.path(Sys.getenv("HOME"), ".R", "Makevars")) 
# to edit the file and give it these contents: 

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

I haven’t seen any examples where R 4.0.2 combined with that Makevars file fails on Mac (unless you get an error like Some models run without problems, but more complex give error: Error in unserialize(socklist[[n]]) : error reading/writing from connection, in which case @torkar mentioned that removing -march=native can solve that on Mac).

I meant to mention in my previous post, that if you really don’t want to upgrade to the latest R, you can use our new CmdStanR interface to run Stan from R, which I think should be fine with R 3.6.

1 Like

Hi Jonah,
Sorry for the late reply. I don’t work on weekends :).
In the end I installed R 4.0.2 and it worked.
Thank you very much!

1 Like

@andrjohns Im having this issue on my windows PC. Trying to run brm( ) function in the brms package. It says Compiling Stan program... but nothing happens

What happens if you run:

example(stan_model,package="rstan",run.dontrun=TRUE,verbose=TRUE)