Problems with crashing R session

I uninstalled R and RStudio, also deleted any files or old version library remnants. And I installed R (4.0.4) and RStudio (1.4.1103) again. Then I installed the rstan package, and the error was shown (there is no package called ‘RcppParallel’).

Erro: package or namespace load failed for ‘StanHeaders’ in loadNamespace(j ← i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
there is no package called ‘RcppParallel’

I tried to install RcppParallel package using the command:

remotes::install_github(“hsbadr/RcppParallel@develop”, force = TRUE)

And the error this time was:

Error: Failed to install ‘RcppParallel’ from GitHub:
(converted from notice) installation of package ‘C:/Users/CARLOS~1/AppData/Local/Temp/RtmpqoG4lC/file1ae4270ffe1/RcppParallel_5.1.0-9000.tar.gz’ had non-zero exit status

I did what was recommended.

install the GIT (Git - Downloading Package)
install.packages(“git2r”)
remotes::install_github(“hsbadr/RcppParallel@develop”, force = TRUE)

The RcppParallel package is now installed and the recommended version v5.1.0.9000. But when compiling the stan model [stan_model ()] from the example script, it has shown the following warning

Warning message:
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
‘C:/rtools40/usr/mingw_/bin/g++’ not found

Now I started a new R session, deleted the .rds file from my stan model to be copied again. And the stan_model () function showed me the error again.


Error in inDL(x, as.logical(local), as.logical(now), …) :
unable to load shared object
‘C:/Users/CARLOS~1/AppData/Local/Temp/RtmpUHSA6Y/file9ac5c21ab.dll’:
LoadLibrary failure: A dynamic link library (DLL) initialization routine has failed.
Além disso: Warning message:
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
‘C:/rtools40/usr/mingw_/bin/g++’ not found
Error in sink(type = “output”) : invalid connection

You don’t have a C++ compiler installed. Check your Rtools installation (here) and make sure that g++ is installed and available in R:

Sys.which("g++")
2 Likes

Ok. I already had Rtools40 installed but uninstalled and reinstalled to make sure. And I followed all the steps suggested in the link sent.

About “g++”


g++
“”

Possibly the problem is in it, right. What should I do now?

That warning (C:/rtools40/usr/mingw_/bin/g++) is safe to ignore, but it indicates that you’re using RStan 2.21, not the 2.26 preview.

What do you get from:

packageVersion("rstan")

If it’s not 2.26.x then you’ll need to follow the installation instructions again

Exactly, my version is 2.21
what I get is the output: ‘2.21.2’.
I looked for instructions for the new version of rstan 2.26 as indicated and are not quite clear.
So that I can do everything correctly you could guide me on how I remove the current version (2.21.2) and install the new version, please.

First of all, thank you for your attention.

That was these:

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")))

Making sure that this is a fresh R session and that rstan is not loaded

1 Like

Okay, I installed everything, I made sure of all the recommendations made, including the version. But it is incredible, the problem of crashing RStudio session still persists.

And to confirm, there isn’t a crash for the example model:

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

Only for your model? Does the crash occur at the stan_model call or the sampling call?

Exactly. the example model of the stan works perfectly. It is only with the non-linear models (my model). The crash occur just with sampling() function or with stan(), but not with stan_model() function.

I haven’t been able to replicate the crashes with your model on two computers and across Windows and Linux, so I think there’s something unique about your system that’s causing issues. I suspect if you can run your model on a different OS/computer it will be fine.

For this setup, a couple of other things to look into.

  • Try copying your model as a string in R, and then calling stan with the model_code option, like:
modcode <- "functions{ ..."
fit_MMF <- stan(model_code=modcode,data=dat)
  • Try running with only 1 chain to see if there is a different/any error that pops up
  • Try running with only 100 iterations

Also, how much RAM do you have?

1 Like

I’m glad you managed to reproduce the problem (the crashes). Ok, so I’m going to do that. I am going to migrate my operating system to Linux and work on it.

About a couple of other things indicated to investigate, Below some feedback:

  • Try copying your model as a string in R, and then calling stan with the model_code option, like:

When I did that, the same problem occurred (Crashing R session).

  • Try running with only 1 chain to see if there is a different/any error that pops up:

It seems to me that with only one chain it works well. At least, the two attempts that I made now, it worked well.

  • Try running with only 100 iterations:

yeep, with 4 chains and only 100 iterations occurred the crashing R session.

On the question of the amount of RAM, I believe that 34 GB. Below is a picture captured from the Windows configuration.

Perhaps the problem may be in parallel programming?

Oh, no I mean that I wasn’t able to reproduce it.

It seems to me that with only one chain it works well. At least, the two attempts that I made now, it worked well.

Ah that’s interesting. If it works with 1 chain, but not 4 chains with 100 iterations, it’s either an issue with the parallelisation or you have a CPU core that’s failing in some way. Does it crash with 2 chains?

No, my CPU cores are working fine, I believe (see photo).

With regard to running the model with only 2 chains, it also worked well, there is no problem with 2 times attempts (with script exemple) that I did.

Remembering that I had no problems with Stan until before updating R, RStudio and Stan himself.

If two chains works, then there isn’t an issue with the parallelisation. Something else to try, can you edit your Makevars.win to only contain CXX14FLAGS += -O3? You can do this automatically from R via:

dotR <- file.path(Sys.getenv("HOME"), ".R")
M <- file.path(dotR, "Makevars.win")
cat("\n CXX14FLAGS += -O3", file = M, sep = "\n", append = FALSE)
1 Like

The following error occurred.

Error in file(file, ifelse(append, “a”, “w”)) :
it is not possible to open the connection
In addition: Warning message:
In file(file, ifelse(append, “a”, “w”)) :
could not open file ‘D:\Users\Carlos Zarzar\Documents/.R/Makevars.win’: No such file or directory

Hi @andrjohns,
Sorry for the delay to respond.
Yesterday I was working on other things and I didn’t have time to turn on the computer.
My file Makevars.win is located at: D:\Users\Carlos Zarzar\Documents\R\win-library\4.0\RcppEigen\skeleton
I’m not sure if it is the same file you are talking about.

I’m confused, in your earlier post above you had a Makevars.win file. Did you delete it at some point?

No, I did not delete the Makevars.win file.
What I believe is that it is not in that directory pointed to by your command (below):

dotR <- file.path(Sys.getenv("HOME"), ".R")
M <- file.path(dotR, "Makevars.win")
cat("\n CXX14FLAGS += -O3", file = M, sep = "\n", append = FALSE)
  • Because it returns this error:

Error in file(file, ifelse(append, “a”, “w”)) :
it is not possible to open the connection
In addition: Warning message:
In file(file, ifelse(append, “a”, “w”)) :
could not open file ‘D:\Users\Carlos Zarzar\Documents/.R/Makevars.win’: No such file or directory

  • When I looked for the file Makevars.win I found it in:

D:\Users\Carlos Zarzar\Documents\R\win-library\4.0\RcppEigen\skeleton

  • Is that normal?