Error when trying to create R package that involves stan, using rstantools

Just came across this thread. I had a similar issue a while back, with the same “file too big” and “too many sections” error messages, which could seemingly occur at multiple stages in the rstantools build workflow whenever the Stan files are compiled.

Long and painful story short, in my case the problem turned out to be that I was failing to invoke my Makevars.win, to which I’d added a number of -Wno-blahblah flags to suppress the extremely verbose and unhelpful warning messages that (recent versions of?) the compiler toolchain spits out. I don’t expect @anthony_462 or @yyang97 have my particular issue of an overlooked environment variable pointing to a location that is not the customized Makevars.win, but if you’re new to Stan-dependent packages then you likely haven’t added any flags beyond what’s prescribed in the rstantools tutorial. At least in the case of my packages, those minimal flags are not sufficient, and compilation will fail with the same sort of error you’re getting.

Most of that epic thread is me chasing my own tail and is probably not directly applicable, but you might be interested in the GitHub Issues linked in this post, which discuss a closely related problem (in the context of TMB rather than Stan) and some important caveats when adding no-warning flags to Makevars.

If this does turn out to be the issue and my experience could help other users, I’d be thrilled. One way to test it would be to compile lm.stan directly with rstan::stan_model() or rstan::stan(). If the compiler spits out lots of warnings, those are the ones you’re trying to suppress.