R crashing with Rstan/brms

Hello!

I have been running brms without issue for months until I recently updated my brms, rstan, and StanHeaders packages. Now some very simple models work but other models that are slightly more complex but that previously ran easily either make R crash or run in an infinite sampling loop that I must eventually stop. Strangely, the same model will produce either the infinite loop or crash R unreliably. In either case, there are no results.

The only errors that appear are “Warning message:
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
‘C:/rtools40/usr/mingw_/bin/g++’ not found” which my googling has shown should not matter.

Apparently, this is somewhat common but none of the fixes I have seen have worked. I have unsuccessfully tried:

  1. checking my .R/Makevars file
  2. updating my r version
  3. checking that Rtools is on the PATH
  4. running example(stan_model, package = “rstan”, run.dontrun = TRUE)
    The result is a successful run with just the error above

Thank you for any help you can provide!

Here is an example of a model that did not work:

library(brms)
library(mice)

data(“iris”)

#add NAs
iris2 <- iris
iris2$Sepal.Length[5:10]<-NA
iris2$Petal.Length[15:30]<-NA

#Impute missing at random data
imp <- mice(iris2, m = 5, print = FALSE)

#model in which session aborted/loops

fitbrm8 <- brm_multiple(Sepal.Width ~ Sepal.Length+Petal.Length+(1+Sepal.Length+Petal.Length|Species*Petal.Width),
data = imp,
family = gaussian(),
prior = set_prior(“normal(0,5)”),
control = list(adapt_delta = 0.8),
warmup = 100, iter = 200, chains = 3,
cores = 3)


computer stats:

  • Output of writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))
    CXX14FLAGS += -O3 -mtune=native -arch x86_64 -ftemplate-depth-256

  • Output of devtools::session_info("rstan")

  • Session info -----------------------------------------------------------------------
    setting value
    version R version 4.0.3 (2020-10-10)
    os Windows 10 x64
    system x86_64, mingw32
    ui RStudio
    language (EN)
    collate English_United States.1252
    ctype English_United States.1252
    tz America/Los_Angeles
    date 2020-12-18

  • Packages ---------------------------------------------------------------------------
    package * version date lib source
    assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.3)
    backports 1.2.1 2020-12-09 [1] CRAN (R 4.0.3)
    BH 1.72.0-3 2020-01-08 [1] CRAN (R 4.0.3)
    brio 1.1.0 2020-08-31 [1] CRAN (R 4.0.3)
    callr 3.5.1 2020-10-13 [1] CRAN (R 4.0.3)
    checkmate 2.0.0 2020-02-06 [1] CRAN (R 4.0.3)
    cli 2.2.0 2020-11-20 [1] CRAN (R 4.0.3)
    colorspace 2.0-0 2020-11-11 [1] CRAN (R 4.0.3)
    crayon 1.3.4 2017-09-16 [1] CRAN (R 4.0.3)
    curl 4.3 2019-12-02 [1] CRAN (R 4.0.3)
    desc 1.2.0 2018-05-01 [1] CRAN (R 4.0.3)
    diffobj 0.3.2 2020-10-05 [1] CRAN (R 4.0.3)
    digest 0.6.27 2020-10-24 [1] CRAN (R 4.0.3)
    ellipsis 0.3.1 2020-05-15 [1] CRAN (R 4.0.3)
    evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.3)
    fansi 0.4.1 2020-01-08 [1] CRAN (R 4.0.3)
    farver 2.0.3 2020-01-16 [1] CRAN (R 4.0.3)
    ggplot2 3.3.2 2020-06-19 [1] CRAN (R 4.0.3)
    glue 1.4.2 2020-08-27 [1] CRAN (R 4.0.3)
    gridExtra 2.3 2017-09-09 [1] CRAN (R 4.0.3)
    gtable 0.3.0 2019-03-25 [1] CRAN (R 4.0.3)
    inline 0.3.17 2020-12-01 [1] CRAN (R 4.0.3)
    isoband 0.2.3 2020-12-01 [1] CRAN (R 4.0.3)
    jsonlite 1.7.2 2020-12-09 [1] CRAN (R 4.0.3)
    labeling 0.4.2 2020-10-20 [1] CRAN (R 4.0.3)
    lattice 0.20-41 2020-04-02 [2] CRAN (R 4.0.3)
    lifecycle 0.2.0 2020-03-06 [1] CRAN (R 4.0.3)
    loo 2.4.1 2020-12-09 [1] CRAN (R 4.0.3)
    magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.0.3)
    MASS 7.3-53 2020-09-09 [2] CRAN (R 4.0.3)
    Matrix 1.2-18 2019-11-27 [2] CRAN (R 4.0.3)
    matrixStats 0.57.0 2020-09-25 [1] CRAN (R 4.0.3)
    mgcv 1.8-33 2020-08-27 [2] CRAN (R 4.0.3)
    munsell 0.5.0 2018-06-12 [1] CRAN (R 4.0.3)
    nlme 3.1-149 2020-08-23 [2] CRAN (R 4.0.3)
    pillar 1.4.7 2020-11-20 [1] CRAN (R 4.0.3)
    pkgbuild 1.2.0 2020-12-15 [1] CRAN (R 4.0.3)
    pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.3)
    pkgload 1.1.0 2020-05-29 [1] CRAN (R 4.0.3)
    praise 1.0.0 2015-08-11 [1] CRAN (R 4.0.3)
    prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.0.3)
    processx 3.4.5 2020-11-30 [1] CRAN (R 4.0.3)
    ps 1.5.0 2020-12-05 [1] CRAN (R 4.0.3)
    R6 2.5.0 2020-10-28 [1] CRAN (R 4.0.3)
    RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 4.0.3)
    Rcpp 1.0.5 2020-07-06 [1] CRAN (R 4.0.3)
    RcppEigen 0.3.3.9.1 2020-12-17 [1] CRAN (R 4.0.3)
    RcppParallel 5.0.2 2020-06-24 [1] CRAN (R 4.0.3)
    rematch2 2.1.2 2020-05-01 [1] CRAN (R 4.0.3)
    rlang 0.4.9 2020-11-26 [1] CRAN (R 4.0.3)
    rprojroot 2.0.2 2020-11-15 [1] CRAN (R 4.0.3)
    rstan 2.21.2 2020-07-27 [1] CRAN (R 4.0.3)
    rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.0.3)
    scales 1.1.1 2020-05-11 [1] CRAN (R 4.0.3)
    StanHeaders 2.21.0-7 2020-12-17 [1] CRAN (R 4.0.3)
    testthat 3.0.1 2020-12-17 [1] CRAN (R 4.0.3)
    tibble 3.0.4 2020-10-12 [1] CRAN (R 4.0.3)
    utf8 1.1.4 2018-05-24 [1] CRAN (R 4.0.3)
    V8 3.4.0 2020-11-04 [1] CRAN (R 4.0.3)
    vctrs 0.3.6 2020-12-17 [1] CRAN (R 4.0.3)
    viridisLite 0.3.0 2018-02-01 [1] CRAN (R 4.0.3)
    waldo 0.2.3 2020-11-09 [1] CRAN (R 4.0.3)
    withr 2.3.0 2020-09-22 [1] CRAN (R 4.0.3)

[1] C:/Users/karen/OneDrive/Documents/R/win-library/4.0
[2] C:/Program Files/R/R-4.0.3/library

When it comes to Windows issues I’ve never seen @andrjohns fail to help!

2 Likes

Unfortunately I’m not able to replicate the crashes on a Windows 10 machine. I see that your home directory is a OneDrive folder, do you get the same crashes if you disable/pause syncing before running the model?

Do you get the same crashes if you run brms with backend="cmdstanr"?

1 Like

Thank you so much for taking a look at this @andrjohns!

When I tried your first suggestion of pausing OneDrive the infinite loop persisted.

BUT I think we may have found the issue with your second suggestion. When I put backend=“cmdstanr” into the brms equations got the following error.

“Error: Please install the ‘cmdstanr’ package.”

When I tried to install the package, I got the following error:

"Warning in install.packages :

  • package ‘cmdstanr’ is not available for this version of R*

A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages"

I did not find anything on the web page regarding this package.

It’s not available from CRAN (yet), but you can use the instructions in this article to install cmdstanr and cmdstan itself:

1 Like

Thanks for the instructions. When I followed the instructions above I ran

check_cmdstan_toolchain()
and I got
The CmdStan toolchain is setup properly!

but when I tried to set up the path, I couldn’t set the path because in the cmdstanr folder there was no cmdstan-[version] file.

CmdStan path set to: C:/Users/karen/OneDrive/Documents/R/win-library/4.0/cmdstanr
warning message:
Can’t find CmdStan makefile to detect version number. Path may not point to valid installation.

Thoughts? Thanks!

Hmm, were you able to succssfully run install_cmdstan()?

When I just reinstalled it the warning message. I was able to get the correct path now though for cmdstanr-[version]:.

tar.exe: could not chdir to ‘C:/Users/karen/OneDrive/Documents/.cmdstanr/cmdstan-2.25.0’
Error: Problem extracting tarball. Exited with return code: 1
In addition: Warning message:
In utils::untar(dest_file, exdir = dir_cmdstan, extras = “–strip-components 1”) :
‘tar.exe -xf “C:\Users\karen\OneDrive\Documents/.cmdstanr/cmdstan-2.25.0.tar.gz” -C “C:/Users/karen/OneDrive/Documents/.cmdstanr/cmdstan-2.25.0” --strip-components 1’ returned error code 1

Thanks for sharing the error message. @rok_cesnovar Have you seen this before? Looks like an error extracting the cmdstan tarball on Windows (although I’m not sure if it’s Windows or something else that’s the problem).

I have not seen this one before. To me it seems like permission issues. If not, then a wild guess is no space on the disk?

@KAtkin can you try

file.access("C:/Users/karen/OneDrive/Documents/", mode = 2)
file.access("C:/Users/karen/OneDrive/Documents/.cmdstanr", mode = 2)

Thanks.

1 Like

Could the original issue (not the installation issues) be related to this issue when compiling the same model a second time?

Hello,

Thank you all for your continuing help.

When I tried what @rok_cesnovar suggested I got the following:

  • file.access(“C:/Users/karen/OneDrive/Documents/”, mode = 2)
    C:/Users/karen/OneDrive/Documents/
    0

  • file.access(“C:/Users/karen/OneDrive/Documents/.cmdstanr”, mode = 2)
    C:/Users/karen/OneDrive/Documents/.cmdstanr
    0
    As I understand it “0” means I have access so I moved on.

  • I was correct in that I didn’t have much space on my drive. Thus, I cleared it out and tried to run install_cmdstan() again. I got the new error below:

task.o: duplicate section .rdata$_ZTIN3tbb4taskE[_ZTIN3tbb4taskE]' has different size arena.o: duplicate section .rdata$_ZTIN3tbb4taskE[_ZTIN3tbb4taskE]’ has different size
scheduler.o: duplicate section `.rdata$_ZTIN3tbb4taskE[_ZTIN3tbb4taskE]’ has different size
mingw32-make[1]: Leaving directory ‘C:/Users/karen/OneDrive/Documents/.cmdstanr/cmdstan-2.25.0/stan/lib/stan_math/lib/tbb’

I also tried to replicate the multiple runs situation that @andrewdolman suggested and couldn’t get out = do.call(brm,test_brm) to work even the first time. Perhaps this is something unrelated though. I included the error below.

  • out = do.call(brm,test_brm)
    Error in rbind(deparse.level, …) :
    numbers of columns of arguments do not match

You can ignore this. This is just info when builiding cmdstan. Everything should work.

Woohoo! I successfully ran the model that originally crashed r.

Thank you so much to @torkar, @andrjohns, @jonah, @rok_cesnovar, and @andrewdolman for all of your help!

Have a happy New Year!

2 Likes