Rstan in Rstudio aborts after applying the pairs() function in a Mac with M1 Pro

Hello,

I installed Rstan in a Macbook Pro (2021) with chip M1 Pro and Rstudio aborts after successfully fitting the model but when using the function pairs() to the Stan fit object.

It took me all day to have Rstan working, because even though I verified the installation with the example given and the eight schools code, when I ran a model of mine that actually runs in an Intel Mac and Ubuntu, Rstudio always aborted. I tried different things that I found online, and then, Rstan finally worked with my model. The truth is that I had to erase the control=list(adapt_delta=0.8) because now I was getting the following error (I do not have some of the information, so I wrote “[ ]” for the missing part):

SAMPLING FOR MODEL 'whatever' NOW (CHAIN 1).
[1] "Error in sampler$call_sampler(args_list[[i]]) : "
[2] " VECTOR_ELT() can only be applied to a 'list', not a '[ ]'"
error occurred during calling the sampler; sampling not done

The problem now is that when I use pairs(fit,pars=‘theta’), Rstudio aborts again. I do not know what to do. I lost all the results because the program aborted and it took hours to run, so I want to be able to trust the installation and be able to choose the adapt_delta parameter as before.

Thank you very much.

Alejandro.

  • Operating System: MacOS Monterey 12.01
  • RStan Version: 2.21.0
  • Output of writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))
    Error in file(con, “r”) : cannot open the connection
    In addition: Warning message:
    In file(con, “r”) :
    cannot open file ‘/Users/al/.R/Makevars’: No such file or directory
  • Output of devtools::session_info("rstan")
    Error in loadNamespace(x) : there is no package called ‘devtools’

Can you try the preview of the next RStan version to see if that helps?

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

Hi, Andrew,

Thank you for the answer. When I install StanHeaders and rstan, I get the warning:

Warning in install.packages :
  unable to access index for repository https://mc-stan.org/r-packages/bin/macosx/big-sur-arm64/contrib/4.1:
  cannot open URL 'https://mc-stan.org/r-packages/bin/macosx/big-sur-arm64/contrib/4.1/PACKAGES'

  There is a binary version available but the source version is later:
              binary source needs_compilation
StanHeaders 2.21.0-7 2.26.4              TRUE

I installed both anyway, but the model cannot be fitted. I can generate the data (using algorithm=fixed_par) but that is all. When I try to fit the model now I get:

Error in stanc(file = file, model_code = model_code, model_name = model_name,  : 
  parser failed badly

Also, if I exit RStudio and open it again, when I try to generate the data again (and the compiled file for the data generation already existed), I get

Error in if (!file.exists(file.rds) || (mtime.rds <- file.info(file.rds)$mtime) <  : 
  missing value where TRUE/FALSE needed

What should I do? I found a post (Sampler won't start if adapt_delta is used: why?) where someone recommends installing development versions. Is that advisable?

Thank you again.

Alejandro.

Hi, again, Andrew,

Did you see my reply?

Thank you.

Alejandro.

hi Alejandro,

have you tried using CmdStanR instead of RStan? it’s not (yet) on CRAN, but it will solve your problem.

Hi, Mitzi,

Thank you for answering so soon. I have not tried it. I will take a look at it.

May you have a nice day.

Alejandro.