I am attempting to run my Stan model via rstan::stan() in the latest version of R (4.3.1), but get the error
Error in dyn.load(libLFile) :
unable to load shared object '/var/folders/r4/xm5blbcd2tn06tjv00lm1c780000gn/T//RtmprSdSql/file95c3479bd57.so':
dlopen(/var/folders/r4/xm5blbcd2tn06tjv00lm1c780000gn/T//RtmprSdSql/file95c3479bd57.so, 0x0006): Library not loaded: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libR.dylib
Referenced from: <00AA8820-6959-3AC7-8CEC-5A3DFEF89645> /private/var/folders/r4/xm5blbcd2tn06tjv00lm1c780000gn/T/RtmprSdSql/file95c3479bd57.so
Reason: tried: '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libR.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libR.dylib' (no such file), '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libR.dylib' (no such file), '/usr/local/lib/libR.dylib' (no such file), '/usr/lib/libR.dylib' (no such file, not in dyld cache)
I’m running on macOS Ventura 13.2 (Apple M2 Pro chip), so selected the appropriate R binary from CRAN (R-4.3.1-arm64.pkg).
Has anyone experienced this issue and knows a solution?
If that doesn’t work then maybe @andrjohns has another idea (he’s better at debugging install issues than I am), or alternatively you could try CmdStanR instead of RStan to run Stan from R.
I had the same issue with rstan not working on my Mac (Intel) with R 4.3.1.
I got it working though by removing the rstan and StanHeaders packages as well as uninstalling R 4.3.1 from my system. A bit of an overkill but I also deleted the “R.framework” folder located through the path Library/Frameworks/.
I then installed R 4.2.3.pkg (for Intel Mac). Also, I made sure the following applications were installed: XQuartz and XCode.
Through RStudio, I installed the latest development version of rstan i.e., 2.26.22 (avoid 2.21.1!) with the following code chunks and tested it which worked!
# install rstan package
install.packages("rstan", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
# code to test if it installed successfully
example(stan_model, package = "rstan", run.dontrun = TRUE)
# you will see a pile of gibberish in rconsole window
# if objects 'fit', 'fit2', 'mod' and 'stancode' appears in environments then rstan package installed successfully!
It’s a bit of a downgrade but perhaps you can try using R 4.2.3. that’s compatible with Mac (M1/2) for now and see if this resolves the problem. Hopefully, it does I’m quite curious to know.