FWIW tiflo’s script runs fine for me on High Sierra (10.13.6).
Some unsolicited advice, I would try running this using rscript and not within Rstudio. Calling Stan lots of times from within a single Rstudio instance has caused me a lot of pain in the past.
Sorry to be slow. I cranked my back and have limited mobility (R crashed me ;)).
I can add that I had completely reinstalled R, c++, and rstan recently. I’m running MacOS High Sierra 10.13.6 (17G65) on a MacPro (2.7 GHz 12-Core Intel Xeon E5, 64 GB 1866 MHz DDR3).
platform x86_64-apple-darwin15.6.0
arch x86_64
os darwin15.6.0
system x86_64, darwin15.6.0
status
major 3
minor 5.2
year 2018
month 12
day 20
svn rev 75870
language R
version.string R version 3.5.2 (2018-12-20)
nickname Eggshell Igloo
I then restarted R and R studio (not sure whether I also would need to restart the computer?). This still yields the same error (and at the same place in the script).
I had a similar problem where I wanted to use the same model to run a simulation a 17000 times without recompilation. It always crashed after the 1000th run even when I used a different computer and OS.
My solution was to use rslurm to parallelise the R code and ran everything on our HPC.That worked perfectly. I didn’t have time to test it but maybe it would even work using other kinds of parallelisation or functions like lapply() instead of a for loop.