Error: Expected end of file after end of generated quantities block

Short summary of the problem:
Getting error running rstan or saving stan files - not finding an End of file

I’m on a MacBook Pro with the M1 Max Chip. Due to earlier issues, I’m running:
rstan version 2.26.6 (Stan version 2.26.1)

I’m trying to edit a stan file that works fine. But even with a small change in the code - like changing the defined range of a variable - I get a parsing error: “Expected end of file after end of generated quantities block.” Sometimes a small change will get a “syntactically correct” message when saving but still get this error when running the file.

1 Like

The last bit - getting a correct message then it still bombing - didn’t happen after starting a new session.

it sounds like you’ve got one too many close brackets somewhere in your code.

the parser is going through the GQ block and hits the closing “}”, it can’t handle anything other than trailing whitespace after that, so when it gets more Stan code, it throws an error.

Maybe so. There don’t seem to be now. But the RStudio session seems to be sticky on errors. Even when they are corrected I still get the same error messages.

This is unfortunately a known error with the new rstan 2.26, where if the parser encounters an error, then all future models (even if correct) will also error. The only solution at this point is to restart the R session.

@hsbadr did we have a workaround for this yet?

1 Like

Ok - that explains it. thanks.

I believe this issue was resolved by this PR

I could backport this change to the release of 2.26 and give you an updated stancjs if that would be helpful?
@andrjohns @hsbadr

Edit: The alternative solution is to restart the V8 instance between each call to stancjs, which is probably not ideal


rstan/StanHeaders v2.26.7 (Update `rstan`/`StanHeaders` packages v2.26.7 · stan-dev/r-packages@f752a4f · GitHub) is ready for testing:

remove.packages(c("rstan", "StanHeaders"))
install.packages("StanHeaders", repos = c("", getOption("repos")))
install.packages("rstan", repos = c("", getOption("repos")))