Rstan sampling "R session aborted" error

Rstudio displayed an error message as follows with a bomb picture, and sampling failed.
Original data is not permitted to share.

error message
"R Session Aborted
R encountered a fatal error.
The session was terminated".

stan code
data {
int N;
int P;
real A[N];
int<lower=0, upper=10> HA[N];
int<lower=1, upper=P> PREF[N];

parameters {
real b0;
real ba0;
real a00;
real b[P];
real ba[P];
real a0[P];
real<lower=0> s_b;
real<lower=0> s_ba;
real<lower=0> s_a0;
real<lower=0> s_H;

model {
for (p in 1:P) {
b[p] ~ normal(b0, s_b);
ba[p] ~ normal(ba0, s_ba);
a0[p] ~ normal(a00, s_a0);

for (n in 1:N)
HA[n] ~ normal(b[PREF[n]] + ba[PREF[n]] * (A[n] - a0[PREF[n]]) ^ 2, s_H);

generated quantities {
real h_pred[N];
for (n in 1:N)
h_pred[n] = normal_rng(b[PREF[n]] + ba[PREF[n]] * (A[n] - a0[PREF[n]]) ^ 2, s_H);

r code

d <- read.csv(file=‘output/ch2/lall3.csv’, header = TRUE)
d <- subset(d, subset = year == 2013)
d$age_std <-(d$age-mean(d$age))/sd(d$age)

data <- list(N=nrow(d),P=length(levels(d$pref)),A=d$age_std,

stanmodel <- stan_model(file=‘model/ch2/model_ind_hreghap_simp2.stan’)
fit <- sampling(
data = data,
seed =243,
chains=4, iter=1000, warmup=500, thin=1

I tried again with the following codes

rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores())

but, it displayed the following error message

Error in unserialize(socklist[[n]]) : error reading from connection
Error in serialize(data, node$con, xdr = FALSE) :
error writing to connection

I would appreciate it if someone would help me.

Try deleting the model/ch2/model_ind_hreghap_simp2.rds file and try to run it again.

Thank you for your comment.
I deleted the rds file, but unfortunately the same problem still happens.

The system condition is as follows.

R version 3.4.1 (2017-06-30) – "Single Candle"
Platform: x86_64-w64-mingw32/x64 (64-bit)
RStudio: Version 1.0.143
rstan (Version 2.16.2, packaged: 2017-07-03 09:24:58 UTC, GitRev: 2e1f913d3ca3)

Ah. If this is a Windows server, make sure you do not have anything like -mtune=native -march=native under CXXFLAGS in ~/.R/Makevars.


I have found those two under CXXFLAGS.
After deleting them, sampling started properly.
Thank you for your good advice.

I also have the same problem, where is ~/.R/Makevars located in Windows? Thanks

Normally in your Documents folder. Alternatively, the instructions for generating a recommended Makevars are on this page: Configuring C Toolchain for Windows · stan-dev/rstan Wiki · GitHub

Thank you so much!