Error in prep_call_sampler(object) : could not find function "prep_call_sampler"

I’ve just today started trying to use rstan with RStudio. I have been going through the steps as outlined in the “RStan Getting Started.”

RStan Getting Started · stan-dev/rstan Wiki · GitHub.

I’m on a Mac - Ventura. I have restarted R and RStudio multiple times, updated all versions (now R 4.3.1 (2023-06-16) – “Beagle Scouts” and RStudio 2023.06.01+524). I have also updated all packages, and I’ve tried a plethora of troubleshooting options that I have found available. I have not been successful with any.

I am able to install rstan and StanHeaders, and I have gone through the steps for Configuring the C++ Toolchain. On my first attempts, once I got to running

example(stan_model, package = “rstan”, run.dontrun = TRUE)

my RSession aborted every time. After a machine restart and an uninstall/reinstall of rstan, I was able to run the example, but then once I tried to move on to the simple 8 Schools example, I found that RStudio was suppressing errors and was not returning any fit object for

fit ← stan(file = ‘schools.stan’, data = schools_dat)

but it was giving an error only for the first chain that said “Error in unserialize(socklist[[n]]) : error reading from connection.” Unlike other posts that described this issue, it still ran through the other chains but did not return an object.

After some more troubleshooting and restarts, I am now back to being unable to run the

example(stan_model, package = “rstan”, run.dontrun = TRUE)

Specifically, I get the error that says “Error in prep_call_sampler(object) : could not find function “prep_call_sampler””. From my understanding, this can really only happen if rstan is not installed properly, but I’ve tried multiple reinstalls including reinstalls from repo and source all to no avail. If I try the install form repo or source, I also sometimes get an error that StanHeaders is corrupted?

Is there any known fix for this? Any help at all would be appreciated!

The issue is magically resolved - I changed nothing, did one last desperate RStudio restart (I had just done that prior to this post with the same error occurring after the restart) and now both the install verification and the 8 school problem are running with no issues.

Quite frustrating that it seems like these kinds of errors are numerous and there seems to be no real explanation as to how/why they are fixed.

Glad it’s working!

I agree! Sorry for the hassle.