C++ exception rstan error, Stan model does not contain samples. Catalina 10.15.3, rstan 2.21.2

Hi there! I have been trying to use rstan to run my bayesian model, but have been receiving a c++ exception error message and “Stan model does not contain samples”. I am using rstan version 2.21.2, R-3.6.3 on Mac Catalina 10.15.3. Here is some code for the model I’m running, as well as the subsequent error messages. Any help at all would be much appreciated!!

bayes_name <- mm_name(type='bayes', pool_K600='binned',
                      err_obs_iid=TRUE, err_proc_acor=FALSE, err_proc_iid=TRUE, 
                      ode_method = 'trapezoid', deficit_src='DO_mod', engine='stan')

#### Set the model specs. 
bayes_specs <- revise(specs(bayes_name), 
                      burnin_steps=1000, saved_steps=500,
                      day_start=3, day_end=27,
                      GPP_daily_mu = 1, GPP_daily_lower = 0,GPP_daily_sigma = 2,
                      ER_daily_mu = -6, ER_daily_upper = 0, ER_daily_sigma = 3,
                      K600_lnQ_nodes_centers= log(pred_K$discharge),
                      K600_lnQ_nodes_meanlog= log(pred_K$K.600.fit),
                      K600_daily_sigma_sigma=0.7, chains=1) #

#run the model with the specs
bayes_fit_kup <- metab(bayes_specs, data=dat_bayes)

Chain 1: Iteration:    1 / 1500 [  0%]  (Warmup)
[1] "Error in sampler$call_sampler(args_list[[i]]) : "
[2] "  c++ exception (unknown reason)"                
error occurred during calling the sampler; sampling not done
here are whatever error messages were returned
`data_frame()` is deprecated as of tibble 1.1.0.
Please use `tibble()` instead.
This warning is displayed once every 8 hours.
Call `lifecycle::last_warnings()` to see where this warning was generated.Modeling failed
    some chains had errors; consider specifying chains = 1 to debug
    Stan model 'b_Kb_oipi_tr_plrckm' does not contain samples.

Getting Stan stuff to work with R 3.x on Macs is not impossible but it is very difficult. In contrast, it is fairly easy if you upgrade to R 4.x, in which case you basically just need Xcode and to delete ~/.R/Makevars and ~/.Renviron . Is there a strong reason why you cannot upgrade to the latest R?

Hi there! Thank you for your response. I was concerned with the compatibility of my current code with R 4.x but if it’s a generally seamless transition I can give it a shot. Do R upgrades tend to require alterations to code written in older versions?


Thank you for your help. I just updated to R 4.0.3 and am now having trouble even installing stan. The Rcpp, Rcpparmadillo, and xcode toolchains have all been downloaded, but I keep getting an error that reads as below. Any recommendations on installing on R 4.0.3 Catalina mac?

"clang: error: no such file or directory: '/Library/Frameworks/R.framework/Resources/lib/libc++abi.1.dylib'
make: *** [rstan.so] Error 1
ERROR: compilation failed for package ‘rstan’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/rstan’

when i use the call:

install.packages("rstan", repos = "https://cloud.r-project.org/", dependencies = TRUE)

Delete the ~/.R/Makevars and ~/.Renviron files.

I deleted the environment file but didn’t “have permission” to delete the makevars. According to earlier inquiries, my makevars code appears correct:

# clang: start
CFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CCFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CXXFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CPPFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include

SHLIB_CXXLDFLAGS+=-Wl,-rpath,${R_HOME}/lib ${R_HOME}/lib/libc++abi.1.dylib
SHLIB_CXX14LDFLAGS+=-Wl,-rpath,${R_HOME}/lib ${R_HOME}/lib/libc++abi.1.dylib
# clang: end

if this is incorrect should i just delete the code in the makevars file and proceed with attempting to install rstan?

You may have to use sudo to delete the file, but you shouldn’t have any of that to use rstan with R 4.x.