paul-buerkner / brms

brms R package for Bayesian generalized multivariate non-linear multilevel models using Stan
https://paul-buerkner.github.io/brms/
GNU General Public License v2.0
1.28k stars 181 forks source link

Error in brms cmpilation #1526

Closed AruhoTinka closed 1 year ago

AruhoTinka commented 1 year ago

Dear GitHub community, I am a beginner with BRMS and I can't understand this error below, and how to rectify it, I need help (my R code that resulted in the error after compilation is also here below.

#######R-code########

practice with brms

date: 07 july 2023

library(ProbBayes) library(brms) library(dplyr) library(ggplot2)

import own data

practc <- read.csv("D:/DESKTOP/UCT 2023/R-Final/Imputedpaxdata_CatData.csv")

setwd("D:/DESKTOP/UCT 2023/R-Final")

non-informative priors

fit_CFC_pref <- brm(CFCPref.~ Age + Gender + Education + Netindv..Inc. + Days.wk + daily_taxifares

Error in compileCode(f, code, language = language, verbose = verbose) : C:/rtools40/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: file1a304d8c7d.o:file1a304d8c7d.cpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D0Ev[_ZN3tbb8internal26task_scheduler_observer_v3D0Ev]+0x1d): undefined reference to tbb::internal::task_scheduler_observer_v3::observe(bool)'C:/rtools40/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: file1a304d8c7d.o:file1a304d8c7d.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x1d): undefined reference totbb::internal::task_scheduler_observer_v3::observe(bool)'C:/rtools40/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: file1a304d8c7d.o:file1a304d8c7d.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x3a): undefined reference to `tbb::internal::task_scheduler_observer_v3::observ Error in sink(type = "output") : invalid connection ################

Thank you

Aruho

lunafazio commented 1 year ago

Hi, did you test if at least the documentation examples can run? e.g.

library(brms)
prior1 <- prior(normal(0,10), class = b) +
  prior(cauchy(0,2), class = sd)
fit1 <- brm(count ~ zAge + zBase * Trt + (1|patient),
            data = epilepsy, family = poisson(), prior = prior1)

If the above doesn't work, try setting options(brms.backend = "cmdstanr") before attempting to fit the model.

As an aside, I suggest renaming your variables to remove dots and underscores beforehand, using those symbols in formulas can cause some issues.

AruhoTinka commented 1 year ago

Thank you, BMFazio, I tried the recommendations, but it still fails, with the following error: ################################################### install_cmdstan(cores = 2) The C++ toolchain required for CmdStan is setup properly!

Attaching package: ‘brms’

The following object is masked from ‘package:stats’:

ar

Warning messages: 1: package ‘brms’ was built under R version 4.2.3 2: package ‘Rcpp’ was built under R version 4.2.3

prior1 <- prior(normal(0,10), class = b) +

  • prior(cauchy(0,2), class = sd) fit1 <- brm(count ~ zAge + zBase * Trt + (1|patient),
  • data = epilepsy, family = poisson(), prior = prior1) Compiling Stan program... make cmd is make -f "C:/PROGRA~1/R/R-42~1.0/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-42~1.0/share/make/winshlib.mk" CXX='$(CXX14) $(CXX14STD)' CXXFLAGS='$(CXX14FLAGS)' CXXPICFLAGS='$(CXX14PICFLAGS)' SHLIB_LDFLAGS='$(SHLIB_CXX14LDFLAGS)' SHLIB_LD='$(SHLIB_CXX14LD)' SHLIB="file9c027762133.dll" WIN=64 TCLBIN= OBJECTS="file9c027762133.o"

make would use if test "zfile9c027762133.o" != "z"; then \ if test -e "file9c027762133-win.def"; then \ echo g++ -shared -s -static-libgcc -o file9c027762133.dll file9c027762133-win.def file9c027762133.o -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib" -L"C:/PROGRA~1/R/R-42~1.0/bin/x64" -lR ; \ g++ -shared -s -static-libgcc -o file9c027762133.dll file9c027762133-win.def file9c027762133.o -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib" -L"C:/PROGRA~1/R/R-42~1.0/bin/x64" -lR ; \ else \ echo EXPORTS > tmp.def; \ nm file9c027762133.o | sed -n 's/^. [BCDRT] / /p' | sed -e '/[.]refptr[.]/d' -e '/[.]weak[.]/d' | sed 's/[^ ][^ ]/"&"/g' >> tmp.def; \ echo g++ -shared -s -static-libgcc -o file9c027762133.dll tmp.def file9c027762133.o -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib" -L"C:/PROGRA~1/R/R-42~1.0/bin/x64" -lR ; \ g++ -shared -s -static-libgcc -o file9c027762133.dll tmp.def file9c027762133.o -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib" -L"C:/PROGRA~1/R/R-42~1.0/bin/x64" -lR ; \ rm -f tmp.def; \ fi \ fi Error in compileCode(f, code, language = language, verbose = verbose) : C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file9c027762133.o:file9c027762133.cpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D0Ev[_ZN3tbb8internal26task_scheduler_observer_v3D0Ev]+0x1d): undefined reference to tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file9c027762133.o:file9c027762133.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x1d): undefined reference totbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file9c027762133.o:file9c027762133.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x3a): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file9c027762133.o:file9c027762133.cpp:(.text$ZN3tbb10interface623task Error in sink(type = "output") : invalid connection #######################################################################

Thanks. Aruho

lunafazio commented 1 year ago

Hmm. It seems that CmdStan did not install properly, so it won't run with the cmdstanr backend, but that is a separate problem.

I have done some local testing and managed to reproduce your error message, so I am almost certain that your initial issue is being caused by rstan. I assume you installed the CRAN version i.e. used install.packages("rstan"). The issue is fixed in the latest development version, please follow this guide to obtain it (version 2.26) and continue with the rest of the steps to ensure that everything else is properly configured, including running the test models.

AruhoTinka commented 1 year ago

Dear BmFazio,

I installed the latest version, 2.26, after installing the newest version of R (4.3.1) and Rstudio. However, it brings the same error: failing to download the "cmdstan" and asking for a retry. I checked the location of the failed download and found it had partially downloaded with 36MB. I manually downloaded the "cmdstan-2.32.2.tar.gz" with 48.1MBs and replaced it with the partially downloaded one. But on retrying, it brings the same error as below. ############################################################################ library(cmdstanr) This is cmdstanr version 0.5.3

Attaching package: ‘posterior’

The following objects are masked from ‘package:stats’:

mad, sd, var

The following objects are masked from ‘package:base’:

%in%, match

library(bayesplot) This is bayesplot version 1.10.0

  • Online documentation and vignettes at mc-stan.org/bayesplot
  • bayesplot theme set to bayesplot::theme_default()
  • Does not affect other ggplot2 plots
  • See ?bayesplot_theme_set for details on theme setting

Attaching package: ‘bayesplot’

The following object is masked from ‘package:posterior’:

rhat

color_scheme_set("brightblue") check_cmdstan_toolchain() The C++ toolchain required for CmdStan is setup properly! install_cmdstan(cores = 2) The C++ toolchain required for CmdStan is setup properly!

  • Latest CmdStan release is v2.32.2
  • Installing CmdStan v2.32.2 in C:/Users/User/OneDrive - University of Cape Town/Documents/.cmdstan/cmdstan-2.32.2
  • Downloading cmdstan-2.32.2.tar.gz from GitHub... Error: Download of CmdStan failed. Please try again.

###################################################### Kindly advise

I thank you. Aruho

lunafazio commented 1 year ago

If you have installed rstan 2.26, then it should not be a problem to run the examples without installing cmdstanr. You haven't mentioned if you also ran the test models in the link I sent or if you were still getting an error. Either way, I would expect the model you initially posted to work properly now that you updated rstan.

If this hasn't resolved your issue, I suggest you post a followup on the Stan forums (https://discourse.mc-stan.org) as this is unlikely to be a problem with brms itself.

AruhoTinka commented 1 year ago

Dear BMFazio, Yes, I ran it initially, it didnt give anything tangible. But this time it posted a file of "2 obs of 10 variables" on the global environment. I reloaded Rtools with the recent one - Rtools43, and reloaded rstan and here below are the results it gave me. I am I good to go, with this output? I see there are still some errors. kindly advise. ###################

install.packages("rstan", repos = "https://cloud.r-project.org/", dependencies = TRUE) WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding: https://cran.rstudio.com/bin/windows/Rtools/ Installing package into ‘C:/Users/User/AppData/Local/R/win-library/4.3’ (as ‘lib’ is unspecified) also installing the dependencies ‘RUnit’, ‘rstudioapi’ There is a binary version available but the source version is later: binary source needs_compilation rstudioapi 0.14 0.15.0 FALSE trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.3/RUnit_0.4.32.zip' Content type 'application/zip' length 296748 bytes (289 KB) downloaded 289 KB trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.3/rstan_2.21.8.zip' Content type 'application/zip' length 3352800 bytes (3.2 MB) downloaded 3.2 MB package ‘RUnit’ successfully unpacked and MD5 sums checked package ‘rstan’ successfully unpacked and MD5 sums checked The downloaded binary packages are in C:\Users\User\AppData\Local\Temp\RtmpMbFSFl\downloaded_packages installing the source package ‘rstudioapi’ trying URL 'https://cloud.r-project.org/src/contrib/rstudioapi_0.15.0.tar.gz' Content type 'application/x-gzip' length 115689 bytes (112 KB) downloaded 112 KB * installing *source* package 'rstudioapi' ... ** package 'rstudioapi' successfully unpacked and MD5 sums checked ** using staged installation ** R ** inst ** byte-compile and prepare package for lazy loading ** help *** installing help indices *** copying figures ** building package indices ** installing vignettes ** testing if installed package can be loaded from temporary location ** testing if installed package can be loaded from final location ** testing if installed package keeps a record of temporary installation path * DONE (rstudioapi) The downloaded source packages are in ‘C:\Users\User\AppData\Local\Temp\RtmpMbFSFl\downloaded_packages’ > example(stan_model, package = "rstan", run.dontrun = TRUE) Loading required package: StanHeaders Loading required package: ggplot2 rstan (Version 2.21.8, GitRev: 2e1f913d3ca3) For execution on a local, multicore CPU with excess RAM we recommend calling options(mc.cores = parallel::detectCores()). To avoid recompilation of unchanged Stan programs, we recommend calling rstan_options(auto_write = TRUE) Do not specify '-march=native' in 'LOCAL_CPPFLAGS' or a Makevars file stn_md> stancode <- 'data {real y_mean;} parameters {real y;} model {y ~ normal(y_mean,1);}' stn_md> mod <- stan_model(model_code = stancode, verbose = TRUE) TRANSLATING MODEL '73fc79f8b1915e8208c736914c86d1a1' FROM Stan CODE TO C++ CODE NOW. successful in parsing the Stan model '73fc79f8b1915e8208c736914c86d1a1'. COMPILING THE C++ CODE FOR MODEL '73fc79f8b1915e8208c736914c86d1a1' NOW. OS: x86_64, mingw32; rstan: 2.21.8; Rcpp: 1.0.10; inline: 0.3.19 trying URL 'https://cran.rstudio.com/bin/windows/Rtools/rtools43/files/rtools43-5550-5548.exe' Content type 'application/x-msdownload' length 487427824 bytes (464.8 MB) downloaded 464.8 MB trying URL 'https://cran.rstudio.com/bin/windows/Rtools/rtools43/files/rtools43-5550-5548.exe' Content type 'application/x-msdownload' length 487427824 bytes (464.8 MB) downloaded 464.8 MB >> setting environment variables: LOCAL_LIBS = "C:/Users/User/AppData/Local/R/win-library/4.3/rstan/lib/x64/libStanServices.a" -L"C:/Users/User/AppData/Local/R/win-library/4.3/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/User/AppData/Local/R/win-library/4.3/RcppParallel/lib/x64" -ltbb PKG_CPPFLAGS = -I"C:/Users/User/AppData/Local/R/win-library/4.3/Rcpp/include/" -I"C:/Users/User/AppData/Local/R/win-library/4.3/RcppEigen/include/" -I"C:/Users/User/AppData/Local/R/win-library/4.3/RcppEigen/include/unsupported" -I"C:/Users/User/AppData/Local/R/win-library/4.3/BH/include" -I"C:/Users/User/AppData/Local/R/win-library/4.3/StanHeaders/include/src/" -I"C:/Users/User/AppData/Local/R/win-library/4.3/StanHeaders/include/" -I"C:/Users/User/AppData/Local/R/win-library/4.3/RcppParallel/include/" -I"C:/Users/User/AppData/Local/R/win-library/4.3/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -DSTAN_THREADS -DBOOST_NO_AUTO_PTR -include "C:/Users/User/AppData/Local/R/win-library/4.3/StanHeaders/include/stan/math/prim/fun/Eigen.hpp" -std=c++1y >> Program source : 1 : 2 : // includes from the plugin 3 : // [[Rcpp::plugins(cpp14)]] 4 : 5 : 6 : // user includes 7 : #include 8 : #include 9 : #include 10 : #include 11 : #include 12 : // Code generated by Stan version 2.21.0 13 : 14 : #include 15 : 16 : namespace model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1_namespace { 17 : 18 : using std::istream; 19 : using std::string; 20 : using std::stringstream; 21 : using std::vector; 22 : using stan::io::dump; 23 : using stan::math::lgamma; 24 : using stan::model::prob_grad; 25 : using namespace stan::math; 26 : 27 : static int current_statement_begin__; 28 : 29 : stan::io::program_reader prog_reader__() { 30 : stan::io::program_reader reader; 31 : reader.add_event(0, 0, "start", "model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1"); 32 : reader.add_event(3, 1, "end", "model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1"); 33 : return reader; 34 : } 35 : 36 : class model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1 37 : : public stan::model::model_base_crtp { 38 : private: 39 : double y_mean; 40 : public: 41 : model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1(rstan::io::rlist_ref_var_context& context__, 42 : std::ostream* pstream__ = 0) 43 : : model_base_crtp(0) { 44 : ctor_body(context__, 0, pstream__); 45 : } 46 : 47 : model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1(stan::io::var_context& context__, 48 : unsigned int random_seed__, 49 : std::ostream* pstream__ = 0) 50 : : model_base_crtp(0) { 51 : ctor_body(context__, random_seed__, pstream__); 52 : } 53 : 54 : void ctor_body(stan::io::var_context& context__, 55 : unsigned int random_seed__, 56 : std::ostream* pstream__) { 57 : typedef double local_scalar_t__; 58 : 59 : boost::ecuyer1988 base_rng__ = 60 : stan::services::util::create_rng(random_seed__, 0); 61 : (void) base_rng__; // suppress unused var warning 62 : 63 : current_statement_begin__ = -1; 64 : 65 : static const char* function__ = "model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1_namespace::model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1"; 66 : (void) function__; // dummy to suppress unused var warning 67 : size_t pos__; 68 : (void) pos__; // dummy to suppress unused var warning 69 : std::vector vals_i__; 70 : std::vector vals_r__; 71 : local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); 72 : (void) DUMMY_VAR__; // suppress unused var warning 73 : 74 : try { 75 : // initialize data block variables from context__ 76 : current_statement_begin__ = 1; 77 : context__.validate_dims("data initialization", "y_mean", "double", context__.to_vec()); 78 : y_mean = double(0); 79 : vals_r__ = context__.vals_r("y_mean"); 80 : pos__ = 0; 81 : y_mean = vals_r__[pos__++]; 82 : 83 : 84 : // initialize transformed data variables 85 : // execute transformed data statements 86 : 87 : // validate transformed data 88 : 89 : // validate, set parameter ranges 90 : num_params_r__ = 0U; 91 : param_ranges_i__.clear(); 92 : current_statement_begin__ = 1; 93 : num_params_r__ += 1; 94 : } catch (const std::exception& e) { 95 : stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__()); 96 : // Next line prevents compiler griping about no return 97 : throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); 98 : } 99 : } 100 : 101 : ~model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1() { } 102 : 103 : 104 : void transform_inits(const stan::io::var_context& context__, 105 : std::vector& params_i__, 106 : std::vector& params_r__, 107 : std::ostream* pstream__) const { 108 : typedef double local_scalar_t__; 109 : stan::io::writer writer__(params_r__, params_i__); 110 : size_t pos__; 111 : (void) pos__; // dummy call to supress warning 112 : std::vector vals_r__; 113 : std::vector vals_i__; 114 : 115 : current_statement_begin__ = 1; 116 : if (!(context__.contains_r("y"))) 117 : stan::lang::rethrow_located(std::runtime_error(std::string("Variable y missing")), current_statement_begin__, prog_reader__()); 118 : vals_r__ = context__.vals_r("y"); 119 : pos__ = 0U; 120 : context__.validate_dims("parameter initialization", "y", "double", context__.to_vec()); 121 : double y(0); 122 : y = vals_r__[pos__++]; 123 : try { 124 : writer__.scalar_unconstrain(y); 125 : } catch (const std::exception& e) { 126 : stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable y: ") + e.what()), current_statement_begin__, prog_reader__()); 127 : } 128 : 129 : params_r__ = writer__.data_r(); 130 : params_i__ = writer__.data_i(); 131 : } 132 : 133 : void transform_inits(const stan::io::var_context& context, 134 : Eigen::Matrix& params_r, 135 : std::ostream* pstream__) const { 136 : std::vector params_r_vec; 137 : std::vector params_i_vec; 138 : transform_inits(context, params_i_vec, params_r_vec, pstream__); 139 : params_r.resize(params_r_vec.size()); 140 : for (int i = 0; i < params_r.size(); ++i) 141 : params_r(i) = params_r_vec[i]; 142 : } 143 : 144 : 145 : template 146 : T__ log_prob(std::vector& params_r__, 147 : std::vector& params_i__, 148 : std::ostream* pstream__ = 0) const { 149 : 150 : typedef T__ local_scalar_t__; 151 : 152 : local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); 153 : (void) DUMMY_VAR__; // dummy to suppress unused var warning 154 : 155 : T__ lp__(0.0); 156 : stan::math::accumulator lp_accum__; 157 : try { 158 : stan::io::reader in__(params_r__, params_i__); 159 : 160 : // model parameters 161 : current_statement_begin__ = 1; 162 : local_scalar_t__ y; 163 : (void) y; // dummy to suppress unused var warning 164 : if (jacobian__) 165 : y = in__.scalar_constrain(lp__); 166 : else 167 : y = in__.scalar_constrain(); 168 : 169 : // model body 170 : 171 : current_statement_begin__ = 1; 172 : lp_accum__.add(normal_log(y, y_mean, 1)); 173 : 174 : } catch (const std::exception& e) { 175 : stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__()); 176 : // Next line prevents compiler griping about no return 177 : throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); 178 : } 179 : 180 : lp_accum__.add(lp__); 181 : return lp_accum__.sum(); 182 : 183 : } // log_prob() 184 : 185 : template 186 : T_ log_prob(Eigen::Matrix& params_r, 187 : std::ostream* pstream = 0) const { 188 : std::vector vec_params_r; 189 : vec_params_r.reserve(params_r.size()); 190 : for (int i = 0; i < params_r.size(); ++i) 191 : vec_params_r.push_back(params_r(i)); 192 : std::vector vec_params_i; 193 : return log_prob(vec_params_r, vec_params_i, pstream); 194 : } 195 : 196 : 197 : void get_param_names(std::vector& names__) const { 198 : names__.resize(0); 199 : names__.push_back("y"); 200 : } 201 : 202 : 203 : void get_dims(std::vector >& dimss__) const { 204 : dimss__.resize(0); 205 : std::vector dims__; 206 : dims__.resize(0); 207 : dimss__.push_back(dims__); 208 : } 209 : 210 : template 211 : void write_array(RNG& base_rng__, 212 : std::vector& params_r__, 213 : std::vector& params_i__, 214 : std::vector& vars__, 215 : bool include_tparams__ = true, 216 : bool include_gqs__ = true, 217 : std::ostream* pstream__ = 0) const { 218 : typedef double local_scalar_t__; 219 : 220 : vars__.resize(0); 221 : stan::io::reader in__(params_r__, params_i__); 222 : static const char* function__ = "model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1_namespace::write_array"; 223 : (void) function__; // dummy to suppress unused var warning 224 : 225 : // read-transform, write parameters 226 : double y = in__.scalar_constrain(); 227 : vars__.push_back(y); 228 : 229 : double lp__ = 0.0; 230 : (void) lp__; // dummy to suppress unused var warning 231 : stan::math::accumulator lp_accum__; 232 : 233 : local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); 234 : (void) DUMMY_VAR__; // suppress unused var warning 235 : 236 : if (!include_tparams__ && !include_gqs__) return; 237 : 238 : try { 239 : if (!include_gqs__ && !include_tparams__) return; 240 : if (!include_gqs__) return; 241 : } catch (const std::exception& e) { 242 : stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__()); 243 : // Next line prevents compiler griping about no return 244 : throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); 245 : } 246 : } 247 : 248 : template 249 : void write_array(RNG& base_rng, 250 : Eigen::Matrix& params_r, 251 : Eigen::Matrix& vars, 252 : bool include_tparams = true, 253 : bool include_gqs = true, 254 : std::ostream* pstream = 0) const { 255 : std::vector params_r_vec(params_r.size()); 256 : for (int i = 0; i < params_r.size(); ++i) 257 : params_r_vec[i] = params_r(i); 258 : std::vector vars_vec; 259 : std::vector params_i_vec; 260 : write_array(base_rng, params_r_vec, params_i_vec, vars_vec, include_tparams, include_gqs, pstream); 261 : vars.resize(vars_vec.size()); 262 : for (int i = 0; i < vars.size(); ++i) 263 : vars(i) = vars_vec[i]; 264 : } 265 : 266 : std::string model_name() const { 267 : return "model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1"; 268 : } 269 : 270 : 271 : void constrained_param_names(std::vector& param_names__, 272 : bool include_tparams__ = true, 273 : bool include_gqs__ = true) const { 274 : std::stringstream param_name_stream__; 275 : param_name_stream__.str(std::string()); 276 : param_name_stream__ << "y"; 277 : param_names__.push_back(param_name_stream__.str()); 278 : 279 : if (!include_gqs__ && !include_tparams__) return; 280 : 281 : if (include_tparams__) { 282 : } 283 : 284 : if (!include_gqs__) return; 285 : } 286 : 287 : 288 : void unconstrained_param_names(std::vector& param_names__, 289 : bool include_tparams__ = true, 290 : bool include_gqs__ = true) const { 291 : std::stringstream param_name_stream__; 292 : param_name_stream__.str(std::string()); 293 : param_name_stream__ << "y"; 294 : param_names__.push_back(param_name_stream__.str()); 295 : 296 : if (!include_gqs__ && !include_tparams__) return; 297 : 298 : if (include_tparams__) { 299 : } 300 : 301 : if (!include_gqs__) return; 302 : } 303 : 304 : }; // model 305 : 306 : } // namespace 307 : 308 : typedef model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1_namespace::model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1 stan_model; 309 : 310 : #ifndef USING_R 311 : 312 : stan::model::model_base& new_model( 313 : stan::io::var_context& data_context, 314 : unsigned int seed, 315 : std::ostream* msg_stream) { 316 : stan_model* m = new stan_model(data_context, seed, msg_stream); 317 : return *m; 318 : } 319 : 320 : #endif 321 : 322 : 323 : 324 : #include 325 : 326 : struct stan_model_holder { 327 : stan_model_holder(rstan::io::rlist_ref_var_context rcontext, 328 : unsigned int random_seed) 329 : : rcontext_(rcontext), random_seed_(random_seed) 330 : { 331 : } 332 : 333 : //stan::math::ChainableStack ad_stack; 334 : rstan::io::rlist_ref_var_context rcontext_; 335 : unsigned int random_seed_; 336 : }; 337 : 338 : Rcpp::XPtr model_ptr(stan_model_holder* smh) { 339 : Rcpp::XPtr model_instance(new stan_model(smh->rcontext_, smh->random_seed_), true); 340 : return model_instance; 341 : } 342 : 343 : Rcpp::XPtr fit_ptr(stan_model_holder* smh) { 344 : return Rcpp::XPtr(new rstan::stan_fit(model_ptr(smh), smh->random_seed_), true); 345 : } 346 : 347 : std::string model_name(stan_model_holder* smh) { 348 : return model_ptr(smh).get()->model_name(); 349 : } 350 : 351 : RCPP_MODULE(stan_fit4model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1_mod){ 352 : Rcpp::class_("stan_fit4model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1") 353 : .constructor() 354 : .method("model_ptr", &model_ptr) 355 : .method("fit_ptr", &fit_ptr) 356 : .method("model_name", &model_name) 357 : ; 358 : } 359 : 360 : 361 : // declarations 362 : extern "C" { 363 : SEXP file1450125dbc( ) ; 364 : } 365 : 366 : // definition 367 : SEXP file1450125dbc() { 368 : return Rcpp::wrap("73fc79f8b1915e8208c736914c86d1a1"); 369 : } make cmd is make -f "C:/PROGRA~1/R/R-43~1.1/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-43~1.1/share/make/winshlib.mk" CXX='$(CXX14) $(CXX14STD)' CXXFLAGS='$(CXX14FLAGS)' CXXPICFLAGS='$(CXX14PICFLAGS)' SHLIB_LDFLAGS='$(SHLIB_CXX14LDFLAGS)' SHLIB_LD='$(SHLIB_CXX14LD)' SHLIB="file1450125dbc.dll" WIN=64 TCLBIN= OBJECTS="file1450125dbc.o" make would use Warning message: In system(paste(cmd, "-n")) : 'make' not found ERROR(s) during compilation: source code errors or compiler configuration errors! Program source: 1: 2: // includes from the plugin 3: // [[Rcpp::plugins(cpp14)]] 4: 5: 6: // user includes 7: #include 8: #include 9: #include 10: #include 11: #include 12: // Code generated by Stan version 2.21.0 13: 14: #include 15: 16: namespace model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1_namespace { 17: 18: using std::istream; 19: using std::string; 20: using std::stringstream; 21: using std::vector; 22: using stan::io::dump; 23: using stan::math::lgamma; 24: using stan::model::prob_grad; 25: using namespace stan::math; 26: 27: static int current_statement_begin__; 28: 29: stan::io::program_reader prog_reader__() { 30: stan::io::program_reader reader; 31: reader.add_event(0, 0, "start", "model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1"); 32: reader.add_event(3, 1, "end", "model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1"); 33: return reader; 34: } 35: 36: class model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1 37: : public stan::model::model_base_crtp { 38: private: 39: double y_mean; 40: public: 41: model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1(rstan::io::rlist_ref_var_context& context__, 42: std::ostream* pstream__ = 0) 43: : model_base_crtp(0) { 44: ctor_body(context__, 0, pstream__); 45: } 46: 47: model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1(stan::io::var_context& context__, 48: unsigned int random_seed__, 49: std::ostream* pstream__ = 0) 50: : model_base_crtp(0) { 51: ctor_body(context__, random_seed__, pstream__); 52: } 53: 54: void ctor_body(stan::io::var_context& context__, 55: unsigned int random_seed__, 56: std::ostream* pstream__) { 57: typedef double local_scalar_t__; 58: 59: boost::ecuyer1988 base_rng__ = 60: stan::services::util::create_rng(random_seed__, 0); 61: (void) base_rng__; // suppress unused var warning 62: 63: current_statement_begin__ = -1; 64: 65: static const char* function__ = "model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1_namespace::model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1"; 66: (void) function__; // dummy to suppress unused var warning 67: size_t pos__; 68: (void) pos__; // dummy to suppress unused var warning 69: std::vector vals_i__; 70: std::vector vals_r__; 71: local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); 72: (void) DUMMY_VAR__; // suppress unused var warning 73: 74: try { 75: // initialize data block variables from context__ 76: current_statement_begin__ = 1; 77: context__.validate_dims("data initialization", "y_mean", "double", context__.to_vec()); 78: y_mean = double(0); 79: vals_r__ = context__.vals_r("y_mean"); 80: pos__ = 0; 81: y_mean = vals_r__[pos__++]; 82: 83: 84: // initialize transformed data variables 85: // execute transformed data statements 86: 87: // validate transformed data 88: 89: // validate, set parameter ranges 90: num_params_r__ = 0U; 91: param_ranges_i__.clear(); 92: current_statement_begin__ = 1; 93: num_params_r__ += 1; 94: } catch (const std::exception& e) { 95: stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__()); 96: // Next line prevents compiler griping about no return 97: throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); 98: } 99: } 100: 101: ~model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1() { } 102: 103: 104: void transform_inits(const stan::io::var_context& context__, 105: std::vector& params_i__, 106: std::vector& params_r__, 107: std::ostream* pstream__) const { 108: typedef double local_scalar_t__; 109: stan::io::writer writer__(params_r__, params_i__); 110: size_t pos__; 111: (void) pos__; // dummy call to supress warning 112: std::vector vals_r__; 113: std::vector vals_i__; 114: 115: current_statement_begin__ = 1; 116: if (!(context__.contains_r("y"))) 117: stan::lang::rethrow_located(std::runtime_error(std::string("Variable y missing")), current_statement_begin__, prog_reader__()); 118: vals_r__ = context__.vals_r("y"); 119: pos__ = 0U; 120: context__.validate_dims("parameter initialization", "y", "double", context__.to_vec()); 121: double y(0); 122: y = vals_r__[pos__++]; 123: try { 124: writer__.scalar_unconstrain(y); 125: } catch (const std::exception& e) { 126: stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable y: ") + e.what()), current_statement_begin__, prog_reader__()); 127: } 128: 129: params_r__ = writer__.data_r(); 130: params_i__ = writer__.data_i(); 131: } 132: 133: void transform_inits(const stan::io::var_context& context, 134: Eigen::Matrix& params_r, 135: std::ostream* pstream__) const { 136: std::vector params_r_vec; 137: std::vector params_i_vec; 138: transform_inits(context, params_i_vec, params_r_vec, pstream__); 139: params_r.resize(params_r_vec.size()); 140: for (int i = 0; i < params_r.size(); ++i) 141: params_r(i) = params_r_vec[i]; 142: } 143: 144: 145: template 146: T__ log_prob(std::vector& params_r__, 147: std::vector& params_i__, 148: std::ostream* pstream__ = 0) const { 149: 150: typedef T__ local_scalar_t__; 151: 152: local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); 153: (void) DUMMY_VAR__; // dummy to suppress unused var warning 154: 155: T__ lp__(0.0); 156: stan::math::accumulator lp_accum__; 157: try { 158: stan::io::reader in__(params_r__, params_i__); 159: 160: // model parameters 161: current_statement_begin__ = 1; 162: local_scalar_t__ y; 163: (void) y; // dummy to suppress unused var warning 164: if (jacobian__) 165: y = in__.scalar_constrain(lp__); 166: else 167: y = in__.scalar_constrain(); 168: 169: // model body 170: 171: current_statement_begin__ = 1; 172: lp_accum__.add(normal_log(y, y_mean, 1)); 173: 174: } catch (const std::exception& e) { 175: stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__()); 176: // Next line prevents compiler griping about no return 177: throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); 178: } 179: 180: lp_accum__.add(lp__); 181: return lp_accum__.sum(); 182: 183: } // log_prob() 184: 185: template 186: T_ log_prob(Eigen::Matrix& params_r, 187: std::ostream* pstream = 0) const { 188: std::vector vec_params_r; 189: vec_params_r.reserve(params_r.size()); 190: for (int i = 0; i < params_r.size(); ++i) 191: vec_params_r.push_back(params_r(i)); 192: std::vector vec_params_i; 193: return log_prob(vec_params_r, vec_params_i, pstream); 194: } 195: 196: 197: void get_param_names(std::vector& names__) const { 198: names__.resize(0); 199: names__.push_back("y"); 200: } 201: 202: 203: void get_dims(std::vector >& dimss__) const { 204: dimss__.resize(0); 205: std::vector dims__; 206: dims__.resize(0); 207: dimss__.push_back(dims__); 208: } 209: 210: template 211: void write_array(RNG& base_rng__, 212: std::vector& params_r__, 213: std::vector& params_i__, 214: std::vector& vars__, 215: bool include_tparams__ = true, 216: bool include_gqs__ = true, 217: std::ostream* pstream__ = 0) const { 218: typedef double local_scalar_t__; 219: 220: vars__.resize(0); 221: stan::io::reader in__(params_r__, params_i__); 222: static const char* function__ = "model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1_namespace::write_array"; 223: (void) function__; // dummy to suppress unused var warning 224: 225: // read-transform, write parameters 226: double y = in__.scalar_constrain(); 227: vars__.push_back(y); 228: 229: double lp__ = 0.0; 230: (void) lp__; // dummy to suppress unused var warning 231: stan::math::accumulator lp_accum__; 232: 233: local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); 234: (void) DUMMY_VAR__; // suppress unused var warning 235: 236: if (!include_tparams__ && !include_gqs__) return; 237: 238: try { 239: if (!include_gqs__ && !include_tparams__) return; 240: if (!include_gqs__) return; 241: } catch (const std::exception& e) { 242: stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__()); 243: // Next line prevents compiler griping about no return 244: throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); 245: } 246: } 247: 248: template 249: void write_array(RNG& base_rng, 250: Eigen::Matrix& params_r, 251: Eigen::Matrix& vars, 252: bool include_tparams = true, 253: bool include_gqs = true, 254: std::ostream* pstream = 0) const { 255: std::vector params_r_vec(params_r.size()); 256: for (int i = 0; i < params_r.size(); ++i) 257: params_r_vec[i] = params_r(i); 258: std::vector vars_vec; 259: std::vector params_i_vec; 260: write_array(base_rng, params_r_vec, params_i_vec, vars_vec, include_tparams, include_gqs, pstream); 261: vars.resize(vars_vec.size()); 262: for (int i = 0; i < vars.size(); ++i) 263: vars(i) = vars_vec[i]; 264: } 265: 266: std::string model_name() const { 267: return "model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1"; 268: } 269: 270: 271: void constrained_param_names(std::vector& param_names__, 272: bool include_tparams__ = true, 273: bool include_gqs__ = true) const { 274: std::stringstream param_name_stream__; 275: param_name_stream__.str(std::string()); 276: param_name_stream__ << "y"; 277: param_names__.push_back(param_name_stream__.str()); 278: 279: if (!include_gqs__ && !include_tparams__) return; 280: 281: if (include_tparams__) { 282: } 283: 284: if (!include_gqs__) return; 285: } 286: 287: 288: void unconstrained_param_names(std::vector& param_names__, 289: bool include_tparams__ = true, 290: bool include_gqs__ = true) const { 291: std::stringstream param_name_stream__; 292: param_name_stream__.str(std::string()); 293: param_name_stream__ << "y"; 294: param_names__.push_back(param_name_stream__.str()); 295: 296: if (!include_gqs__ && !include_tparams__) return; 297: 298: if (include_tparams__) { 299: } 300: 301: if (!include_gqs__) return; 302: } 303: 304: }; // model 305: 306: } // namespace 307: 308: typedef model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1_namespace::model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1 stan_model; 309: 310: #ifndef USING_R 311: 312: stan::model::model_base& new_model( 313: stan::io::var_context& data_context, 314: unsigned int seed, 315: std::ostream* msg_stream) { 316: stan_model* m = new stan_model(data_context, seed, msg_stream); 317: return *m; 318: } 319: 320: #endif 321: 322: 323: 324: #include 325: 326: struct stan_model_holder { 327: stan_model_holder(rstan::io::rlist_ref_var_context rcontext, 328: unsigned int random_seed) 329: : rcontext_(rcontext), random_seed_(random_seed) 330: { 331: } 332: 333: //stan::math::ChainableStack ad_stack; 334: rstan::io::rlist_ref_var_context rcontext_; 335: unsigned int random_seed_; 336: }; 337: 338: Rcpp::XPtr model_ptr(stan_model_holder* smh) { 339: Rcpp::XPtr model_instance(new stan_model(smh->rcontext_, smh->random_seed_), true); 340: return model_instance; 341: } 342: 343: Rcpp::XPtr fit_ptr(stan_model_holder* smh) { 344: return Rcpp::XPtr(new rstan::stan_fit(model_ptr(smh), smh->random_seed_), true); 345: } 346: 347: std::string model_name(stan_model_holder* smh) { 348: return model_ptr(smh).get()->model_name(); 349: } 350: 351: RCPP_MODULE(stan_fit4model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1_mod){ 352: Rcpp::class_("stan_fit4model14507b6f7d77_73fc79f8b1915e8208c736914c86d1a1") 353: .constructor() 354: .method("model_ptr", &model_ptr) 355: .method("fit_ptr", &fit_ptr) 356: .method("model_name", &model_name) 357: ; 358: } 359: 360: 361: // declarations 362: extern "C" { 363: SEXP file1450125dbc( ) ; 364: } 365: 366: // definition 367: SEXP file1450125dbc() { 368: return Rcpp::wrap("73fc79f8b1915e8208c736914c86d1a1"); 369: } Compilation ERROR, function(s)/method(s) not created! Error in compileCode(f, code, language = language, verbose = verbose) : Error in system(paste(MAKE, p1(paste("-f", shQuote(makefiles))), "compilers"), : 'make' not foundCalls: -> .shlib_internal -> systemExecution halted > install.packages("brms") Installing package into ‘C:/Users/User/AppData/Local/R/win-library/4.3’ (as ‘lib’ is unspecified) trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.3/brms_2.19.0.zip' Content type 'application/zip' length 6510291 bytes (6.2 MB) downloaded 6.2 MB package ‘brms’ successfully unpacked and MD5 sums checked The downloaded binary packages are in C:\Users\User\AppData\Local\Temp\RtmpMbFSFl\downloaded_packages > library(brms) Loading required package: Rcpp Loading 'brms' package (version 2.19.0). Useful instructions can be found by typing help('brms'). A more detailed introduction to the package is available through vignette('brms_overview'). Attaching package: ‘brms’ The following object is masked from ‘package:rstan’: loo The following object is masked from ‘package:stats’: ar > library(brms) > prior1 <- prior(normal(0,10), class = b) + + prior(cauchy(0,2), class = sd) > fit1 <- brm(count ~ zAge + zBase * Trt + (1\|patient), + data = epilepsy, family = poisson(), prior = prior1) Compiling Stan program... make cmd is make -f "C:/PROGRA~1/R/R-43~1.1/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-43~1.1/share/make/winshlib.mk" CXX='$(CXX14) $(CXX14STD)' CXXFLAGS='$(CXX14FLAGS)' CXXPICFLAGS='$(CXX14PICFLAGS)' SHLIB_LDFLAGS='$(SHLIB_CXX14LDFLAGS)' SHLIB_LD='$(SHLIB_CXX14LD)' SHLIB="file14507b0d3c8c.dll" WIN=64 TCLBIN= OBJECTS="file14507b0d3c8c.o" make would use if test "zfile14507b0d3c8c.o" != "z"; then \ if test -e "file14507b0d3c8c-win.def"; then \ echo g++ -shared -s -static-libgcc -o file14507b0d3c8c.dll file14507b0d3c8c-win.def file14507b0d3c8c.o -L"C:/RBuildTools/4.3/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/RBuildTools/4.3/x86_64-w64-mingw32.static.posix/lib" -L"C:/PROGRA~1/R/R-43~1.1/bin/x64" -lR ; \ g++ -shared -s -static-libgcc -o file14507b0d3c8c.dll file14507b0d3c8c-win.def file14507b0d3c8c.o -L"C:/RBuildTools/4.3/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/RBuildTools/4.3/x86_64-w64-mingw32.static.posix/lib" -L"C:/PROGRA~1/R/R-43~1.1/bin/x64" -lR ; \ else \ echo EXPORTS > tmp.def; \ nm file14507b0d3c8c.o \| sed -n 's/^.* [BCDRT] / /p' \| sed -e '/[.]refptr[.]/d' -e '/[.]weak[.]/d' \| sed 's/[^ ][^ ]*/"&"/g' >> tmp.def; \ echo g++ -shared -s -static-libgcc -o file14507b0d3c8c.dll tmp.def file14507b0d3c8c.o -L"C:/RBuildTools/4.3/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/RBuildTools/4.3/x86_64-w64-mingw32.static.posix/lib" -L"C:/PROGRA~1/R/R-43~1.1/bin/x64" -lR ; \ g++ -shared -s -static-libgcc -o file14507b0d3c8c.dll tmp.def file14507b0d3c8c.o -L"C:/RBuildTools/4.3/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/RBuildTools/4.3/x86_64-w64-mingw32.static.posix/lib" -L"C:/PROGRA~1/R/R-43~1.1/bin/x64" -lR ; \ rm -f tmp.def; \ fi \ fi Error in compileCode(f, code, language = language, verbose = verbose) : C:\RBuildTools\4.3\x86_64-w64-mingw32.static.posix\bin/ld.exe: file14507b0d3c8c.o:file14507b0d3c8c.cpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D0Ev[_ZN3tbb8internal26task_scheduler_observer_v3D0Ev]+0x1c): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\RBuildTools\4.3\x86_64-w64-mingw32.static.posix\bin/ld.exe: file14507b0d3c8c.o:file14507b0d3c8c.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x1c): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\RBuildTools\4.3\x86_64-w64-mingw32.static.posix\bin/ld.exe: file14507b0d3c8c.o:file14507b0d3c8c.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x37): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\RBuildTools\4.3\x86_64-w64-mingw32.static.posix\bin/ld.exe: file14507b0d3c8c.o:file14507b0d3c8c.c Error in sink(type = "output") : invalid connection --     |    

############################

Aruho

wds15 commented 1 year ago

This thread looks to me like it belongs onto the Stan forums and not the brms issue tracker.