Able to load rstan, but unable to run stan() funciton

Can you try restarting R, making sure rstan doesn’t get loaded, and reinstall from source:

# Compile packages using all cores
Sys.setenv(MAKEFLAGS = paste0("-j",parallel::detectCores()))

remove.packages(c("StanHeaders","rstan"))
install.packages(c("StanHeaders","rstan"),type="source")

Hi - were you able to solve this? I’m encountering the exact same problem now.

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!

Hi, I got the same issue when updating R 4.0 to R 4.1! Please see Have trouble using RStan for details. Can somebody help me with this?

I too have this problem and I am on R version 4.1.1 (2021-08-10) -- "Kick Things"