So, oddly enough, what ended up working for me was copying-and-pasting my .stan file into a new .stan file in a new directory, and when I told my code to use that new file instead, everything worked fine. It’s a totally mystery as to why a new file/directory solved the issue, when ultimately the code within the .stan file (and corresponding R code) was exactly the same.
This means that I can run stan() just fine using a particular .stan file, but when I change the directory using setwd() (and that directory has the exact same .stan file), I get the error I mentioned in my original post.
Unfortunately, reinstalling rstan (or even R) did not solve the issue, at least for me.
Thanks for this, I encountered the error using the sampling() statement, but I did try to recompile and rename the Stan objects. But it hasn’t made a difference. What helped was when I reverted back to R 4.0. again, because the problem only occurred after I had updated R. Not optimal, but I at least got it running again.
Thanks so much!
I was having this problem. I changed the stan file slightly (e.g., add an arbitrary new line or space) then saved, and then ran stan again. This forces a recompilation. The problem went away.
Thanks @mel. I had the same problem (on R version 4.1.1, macOS Big Sur) and it went away by doing what you suggested – i.e. I added a blank line at the end of the stan file and the problem has gone away.