Array syntax with rstan

I have been using rstan for two years and since last week there have been many troubles with the array syntax. Writing arrays as in the latest Stan manual returns syntax check error, as mentioned in Error in declaring variables by `array` in R · Issue #980 · stan-dev/rstan · GitHub

However, scripts that used to work do not work anymore with the latest rstan. Even when syntax check is passed using the previous version of array syntax, e.g. real x[n], rstan still does not work. Errors appear at the first iteration, i.e. after gradient evaluation etc, and are as follows,

terminate called after throwing an instance of ‘std::bad_alloc’
what(): std::bad_alloc
Error in x@mode :
no applicable method for @ applied to an object of class “NULL”

I’m wondering if this is occurring to anyone else? Any suggestions? Thank you.

@andrjohns @hsbadr

Can you try a clean re-installation of the rstan preview:

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

Then restart R and try your model again? If you still get errors, can you share your model and the error messages and output that are printed?

1 Like

The issue is resolved, thank you so much. I just realized that the Github repository has rstan version 2.26.1 while CRAN latest version is 2.21.8, that makes a huge difference. Thanks again for saving my day.