# Brms Causing R Session Aborted (R Encountered Fatal Error) Only With Control Parameters Included

**URL:** <https://discourse.mc-stan.org/t/brms-causing-r-session-aborted-r-encountered-fatal-error-only-with-control-parameters-included/24361>\
**Category:** brms\
**Tags:** rstan, brms\
**Created:** [September 12, 2021, 10:18pm UTC](https://discourse.mc-stan.org/t/brms-causing-r-session-aborted-r-encountered-fatal-error-only-with-control-parameters-included/24361 "2021-09-12T22:18:14Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![awaldman123](https://avatars.discourse-cdn.com/v4/letter/a/67e7ee/32.png) [@awaldman123](https://discourse.mc-stan.org/u/awaldman123)\
**Post date:** [September 12, 2021, 10:18pm UTC](https://discourse.mc-stan.org/t/brms-causing-r-session-aborted-r-encountered-fatal-error-only-with-control-parameters-included/24361/1 "2021-09-12T22:18:14Z")

</div>

I have been attempting to run a zero-inflated poisson model with the attached data and following code:

[Example.csv](https://discourse.mc-stan.org/uploads/short-url/w1nsBWYH29veydgZdKSUxDmpam7.csv) (21.5 KB)

example\<-read.csv(“Example.csv”,header=T)  
as.factor(example$ID)-\>example$ID  
as.factor(example$Sex)-\>example$Sex  
as.factor(example$Level)-\>example$Level  
as.factor(example$LesionType)-\>example$LesionType

formula\<-bf(LesionNumber ~ Level + LesionType + Level:LesionType + Sex + AgeDeath + DD + PMI + (1 | ID), zi ~ Level + LesionType + Level:LesionType + Sex + AgeDeath + DD + PMI + (1 | ID))

model\<-brm(formula=formula, data=example, family=“zero\_inflated\_poisson”,warmup=2000,iter=4000,seed=34)

I then received errors about treedepth, Rhat, bulk ESS, and tail ESS. Therefore, I tried to adjust the code with the following:

model.updated\<-brm(formula=formula, data=lesion\_number\_total\_staged, family=“zero\_inflated\_poisson”,warmup=4000,iter=8000,seed=34,control=list(max\_treedepth=15))

However, I then get an R Session Aborted error. I’ve never encountered this with recent models and have narrowed down that it only happens when inputting control parameters. Any insight on why this is happening? I’ve tried uninstalling brms, rstan, and rstantools and reinstalling but that didn’t seem to help.

I’m using a MacBook Pro with 16GB memory on Mojave Version 10.14.6 and RStudio version Version 1.4.1717.

---

<div class="post-metadata">

**Author:** ![Solomon](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/solomon/32/2495_2.png) [@Solomon](https://discourse.mc-stan.org/u/Solomon)\
**Post date:** [September 17, 2021, 1:37pm UTC](https://discourse.mc-stan.org/t/brms-causing-r-session-aborted-r-encountered-fatal-error-only-with-control-parameters-included/24361/2 "2021-09-17T13:37:17Z")

</div>

I ran into a similar issue the other week with `adapt_delta` (see [here](https://discourse.mc-stan.org/t/2-16-1-and-adapt-delta/24239/10)). After a lot of fooling around, the quick fix was to install the developmental version of **brms** from GitHub.

```
remotes::install_github("paul-buerkner/brms")

```

---

<div class="post-metadata">

**Author:** ![ulrich.dettweiler](https://avatars.discourse-cdn.com/v4/letter/u/779978/32.png) [@ulrich.dettweiler](https://discourse.mc-stan.org/u/ulrich.dettweiler)\
**Post date:** [November 10, 2021, 8:44am UTC](https://discourse.mc-stan.org/t/brms-causing-r-session-aborted-r-encountered-fatal-error-only-with-control-parameters-included/24361/3 "2021-11-10T08:44:04Z")

</div>

> [@Solomon](#):
>
> `remotes::install_github("paul-buerkner/brms")`

Sorry, did not work for me. Same problem when including the adapt\_delta control. Any more thoughts?

---

<div class="post-metadata">

**Author:** ![Solomon](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/solomon/32/2495_2.png) [@Solomon](https://discourse.mc-stan.org/u/Solomon)\
**Post date:** [November 10, 2021, 2:22pm UTC](https://discourse.mc-stan.org/t/brms-causing-r-session-aborted-r-encountered-fatal-error-only-with-control-parameters-included/24361/4 "2021-11-10T14:22:10Z")

</div>

That’s frustrating. Sadly, that’s all I’ve got on this one.

---

<div class="post-metadata">

**Author:** ![ulrich.dettweiler](https://avatars.discourse-cdn.com/v4/letter/u/779978/32.png) [@ulrich.dettweiler](https://discourse.mc-stan.org/u/ulrich.dettweiler)\
**Post date:** [November 10, 2021, 4:07pm UTC](https://discourse.mc-stan.org/t/brms-causing-r-session-aborted-r-encountered-fatal-error-only-with-control-parameters-included/24361/5 "2021-11-10T16:07:01Z")

</div>

Thanks anyway, Solomon! Much appreciated. I try rstanarm now, however, I liked the possibility for multivariate responses in brms. All the best from Norway, Ulrich

---

<div class="post-metadata">

**Author:** ![t-davidson](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/t-davidson/32/12980_2.png) [@t-davidson](https://discourse.mc-stan.org/u/t-davidson)\
**Post date:** [November 10, 2021, 8:51pm UTC](https://discourse.mc-stan.org/t/brms-causing-r-session-aborted-r-encountered-fatal-error-only-with-control-parameters-included/24361/6 "2021-11-10T20:51:08Z")

</div>

I just updated to R 4.1.2 on an Intel Mac with Big Sur 11.6 and experienced the same issue. Specifying a model with `adapt_delta` caused R Studio to crash. I tried uninstalling `rstan` and `brms` to no avail but Solomon’s solution appears to have worked.

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [November 11, 2021, 12:06am UTC](https://discourse.mc-stan.org/t/brms-causing-r-session-aborted-r-encountered-fatal-error-only-with-control-parameters-included/24361/7 "2021-11-11T00:06:24Z")

</div>

Other users have reported that upgrading to the preview of the next RStan version has solved this problem for them:

```r
remove.packages(c("StanHeaders", "rstan"))
install.packages("StanHeaders", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
install.packages("rstan", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))

```

---

<div class="post-metadata">

**Author:** ![t-pollington](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/t-pollington/32/14497_2.png) [@t-pollington](https://discourse.mc-stan.org/u/t-pollington)\
**Post date:** [July 23, 2022, 1:13pm UTC](https://discourse.mc-stan.org/t/brms-causing-r-session-aborted-r-encountered-fatal-error-only-with-control-parameters-included/24361/8 "2022-07-23T13:13:21Z")

</div>

Unfortunately @Solomon’s package re-installation didn’t work for me. The R session doesn’t abort but a segfault is created. Using `control = list(adapt_delta = 0.95)`. Last chain completes (this happened to be chain 3 this time) and then segfaults reported for all 4 chains. Strangely the `brmsfit` object saves correctly (phew!), which may indicate at what point the segfault occurs.

```nohighlight
Chain 3: Iteration: 100000 / 100000 [100%] (Sampling)
Chain 3: 
Chain 3: Elapsed Time: 753.436 seconds (Warm-up)
Chain 3: 10048.5 seconds (Sampling)
Chain 3: 10801.9 seconds (Total)
Chain 3: 

 ***caught segfault***
address 0x18, cause 'memory not mapped'
An irrecoverable exception occurred. R is aborting now ...

 ***caught segfault***
address 0x18, cause 'memory not mapped'
An irrecoverable exception occurred. R is aborting now ...

 ***caught segfault***
address 0x18, cause 'memory not mapped'
An irrecoverable exception occurred. R is aborting now ...

 ***caught segfault***
address 0x18, cause 'memory not mapped'
An irrecoverable exception occurred. R is aborting now ...
Warning messages:
1: There were 379858 divergent transitions after warmup. See
https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
to find out why this is a problem and how to eliminate them. 
2: Examine the pairs() plot to diagnose sampling problems 

```

R version 4.2.1  
Linux Mint 20.3

---

<div class="post-metadata">

**Author:** ![Garcia48](https://avatars.discourse-cdn.com/v4/letter/g/5fc32e/32.png) [@Garcia48](https://discourse.mc-stan.org/u/Garcia48)\
**Post date:** [August 26, 2023, 7:47pm UTC](https://discourse.mc-stan.org/t/brms-causing-r-session-aborted-r-encountered-fatal-error-only-with-control-parameters-included/24361/9 "2023-08-26T19:47:40Z")

</div>

I have a similar problem, with none of the suggested solutions helping. When I run the following code, it causes the R session to abort.  
library(brms)  
mod ← brm(number\_plants ~ mixture \* seed date, data=dat, family=negbinomial)  
 ![grafik](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/3X/d/6/d6e5f3015f30e533b0e0a3a3af3da3dd725a810b.png)

What could be the cause? I am working with rtools42 and R version 4.3.1

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jonah/32/200_2.png) [@jonah](https://discourse.mc-stan.org/u/jonah)\
**Post date:** [August 27, 2023, 1:06am UTC](https://discourse.mc-stan.org/t/brms-causing-r-session-aborted-r-encountered-fatal-error-only-with-control-parameters-included/24361/10 "2023-08-27T01:06:06Z")

</div>

Does it work if you install this preview version of RStan?

```r
install.packages(c("StanHeaders", "rstan"), repos = c("https://mc-stan.org/r-packages/", getOption("repos")))

```

---

<div class="post-metadata">

**Author:** ![akreutzer82](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/akreutzer82/32/17017_2.png) [@akreutzer82](https://discourse.mc-stan.org/u/akreutzer82)\
**Post date:** [August 29, 2023, 2:08pm UTC](https://discourse.mc-stan.org/t/brms-causing-r-session-aborted-r-encountered-fatal-error-only-with-control-parameters-included/24361/11 "2023-08-29T14:08:29Z")

</div>

I had the same issue. I updated to rtools 4.3 and installed brms and rstan from github with the code provided by jonah above. I also got a popup about windows firewall access this last time. After I allowed access, it all started working.

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jonah/32/200_2.png) [@jonah](https://discourse.mc-stan.org/u/jonah)\
**Post date:** [August 29, 2023, 5:07pm UTC](https://discourse.mc-stan.org/t/brms-causing-r-session-aborted-r-encountered-fatal-error-only-with-control-parameters-included/24361/12 "2023-08-29T17:07:12Z")

</div>

Glad it’s working for you!

---

<div class="post-metadata">

**Author:** ![Garcia48](https://avatars.discourse-cdn.com/v4/letter/g/5fc32e/32.png) [@Garcia48](https://discourse.mc-stan.org/u/Garcia48)\
**Post date:** [August 30, 2023, 12:39pm UTC](https://discourse.mc-stan.org/t/brms-causing-r-session-aborted-r-encountered-fatal-error-only-with-control-parameters-included/24361/13 "2023-08-30T12:39:26Z")

</div>

No, it doesn’t work.

---

<div class="post-metadata">

**Author:** ![Garcia48](https://avatars.discourse-cdn.com/v4/letter/g/5fc32e/32.png) [@Garcia48](https://discourse.mc-stan.org/u/Garcia48)\
**Post date:** [August 30, 2023, 12:54pm UTC](https://discourse.mc-stan.org/t/brms-causing-r-session-aborted-r-encountered-fatal-error-only-with-control-parameters-included/24361/14 "2023-08-30T12:54:46Z")

</div>

the solution was rtools43. I still had rtools42 installed. Sorry!

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jonah/32/200_2.png) [@jonah](https://discourse.mc-stan.org/u/jonah)\
**Post date:** [August 30, 2023, 3:46pm UTC](https://discourse.mc-stan.org/t/brms-causing-r-session-aborted-r-encountered-fatal-error-only-with-control-parameters-included/24361/15 "2023-08-30T15:46:00Z")

</div>

No problem, glad it’s working
