How to fix this compilation error?

I got the following compilation error when running some brms code. How to fix this?

Compiling the C++ model
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! In file included from /usr/include/c++/4.8.2/thread:35:0,
from /usr/lib64/R/library/StanHeaders/include/stan/math/prim/mat/functor/map_rect_concurrent.hpp:10,
from /usr/lib64/R/library/StanHeaders/include/stan/math/prim/mat/functor/map_rect.hpp:13,
from /usr/lib64/R/library/StanHeaders/include/stan/math/prim/mat.hpp:262,
from /usr/lib64/R/library/StanHeaders/include/stan/math/rev/mat.hpp:12,
from /usr/lib64/R/library/StanHeaders/include/stan/math.hpp:4,
from /usr/lib64/R/library/StanHeaders/include/src/stan/model/model_header.hpp:4,
from file34262899c967.cpp:8:
/usr/include/c++/4.8.2/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler o
Calls: brm … cxxfunctionplus → → cxxfunction → compileCode
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘/usr/lib64/R/bin/R CMD SHLIB file34262899c967.cpp 2> file34262899c967.cpp.err.txt’ had status 1
Error in sink(type = “output”) : invalid connection
Calls: brm … eval → do.call → → cxxfunctionplus → sink
Execution halted

  • Operating System: Red Hat 7.5
  • R version: 3.5.1
  • brms Version: 2.6.0

In addition, you likely need CXX14 = g++ -std=c++1y in your ~/.R/Makevars file.

  • Operating System: Red Hat 7.5
  • R version: 3.5.1
  • brms Version: 2.6.0

With the following included in the ~/.R/Makevars file:

CXX14 = g++
CXX14FLAGS = -O3 -march=native -mtune=native -fPIC

I’m still struggling with the following compilation error when running some brms code:

Compiling the C++ model
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! In file included from /usr/lib64/R/library/RcppEigen/include/Eigen/Core:380:0,
from /usr/lib64/R/library/RcppEigen/include/Eigen/Dense:1,
from /usr/lib64/R/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:4,
from /usr/lib64/R/library/StanHeaders/include/stan/math/rev/mat/fun/Eigen_NumTraits.hpp:4,
from /usr/lib64/R/library/StanHeaders/include/stan/math/rev/core/matrix_vari.hpp:4,
from /usr/lib64/R/library/StanHeaders/include/stan/math/rev/core.hpp:14,
from /usr/lib64/R/library/StanHeaders/include/stan/math/rev/mat.hpp:4,
from /usr/lib64/R/library/StanHeaders/include/stan/math.hpp:4,
from /usr/lib64/R/library/StanHeaders/include/src/stan/model/model_header.hpp:4,
from filef4504252e3c6.cpp:8:
/usr/lib64/R/library/RcppEigen/include/Eigen/src/Core/arch/SSE/PacketMa
Calls: brm … cxxfunctionplus → → cxxfunction → compileCode
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘/usr/lib64/R/bin/R CMD SHLIB filef4504252e3c6.cpp 2> filef4504252e3c6.cpp.err.txt’ had status 1
Error in sink(type = “output”) : invalid connection
Calls: brm … eval → do.call → → cxxfunctionplus → sink
Execution halted

What is missing?

Can you do

library(rstan)
stan_model(model_code = make_stancode(...), verbose = TRUE)

calling make_stancode the same way you call brm()?

Here it is:

> library(rstan)
Loading required package: ggplot2
Loading required package: StanHeaders
rstan (Version 2.18.2, 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)

> stan_model(model_code = make_stancode(…), verbose = TRUE)
Error in make_stancode(…) : could not find function “make_stancode”

You would need to do library(brms) first.

The compilation went through almost 2000 lines, and ended up with a similar error as before:

1981: // declarations
1982: extern “C” {
1983: SEXP file9e52590d04aa( ) ;
1984: }
1985:
1986: // definition
1987:
1988: SEXP file9e52590d04aa( ){
1989: return Rcpp::wrap(“2fdbe54e992dce49149926006408144e”);
1990: }
1991:
1992:
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! In file included from /usr/lib64/R/library/RcppEigen/include/Eigen/Core:380:0,
from /usr/lib64/R/library/RcppEigen/include/Eigen/Dense:1,
from /usr/lib64/R/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:4,
from /usr/lib64/R/library/StanHeaders/include/stan/math/rev/mat/fun/Eigen_NumTraits.hpp:4,
from /usr/lib64/R/library/StanHeaders/include/stan/math/rev/core/matrix_vari.hpp:4,
from /usr/lib64/R/library/StanHeaders/include/stan/math/rev/core.hpp:14,
from /usr/lib64/R/library/StanHeaders/include/stan/math/rev/mat.hpp:4,
from /usr/lib64/R/library/StanHeaders/include/stan/math.hpp:4,
from /usr/lib64/R/library/StanHeaders/include/src/stan/model/model_header.hpp:4,
from file9e52590d04aa.cpp:8:
/usr/lib64/R/library/RcppEigen/include/Eigen/src/Core/arch/SSE/PacketMa

You may have to scroll up to find the line that begins with error: (with a colon)

OK, how about this part? In case this is useful, I currently invoke the new C++ compiler through a terminal command of “scl enable devtoolset-7 tcsh”.

file9e52590d04aa.cpp:1990:1: required from here
/usr/lib64/R/library/RcppEigen/include/Eigen/src/Core/DenseCoeffsBase.h:650:34: warning: ignoring attributes on template argument ‘Eigen::internal::packet_traits::type {aka __vector(4) double}’ [-Wignored-attributes]
return internal::first_aligned<int(unpacket_traits::alignment),Derived>(m);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld: file9e52590d04aa.o: relocation R_X86_64_32 against undefined symbol `__pthread_key_create’ can not be used when making a shared object; recompile with -fPIC
/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
make: *** [/usr/share/R/make/shlib.mk:6: file9e52590d04aa.so] Error 1

ERROR(s) during compilation: source code errors or compiler configuration errors!

You need

CXX14FLAGS += -fPIC

in your ~/.R/Makevars file.

Hi!

I believe I have a similar issue.

I am working with R version 3.5.1, brms version 2.7.0, rstan version 2.18.1 and on a Windows 10 operating system.

When I want to fit a brm model or using the alternative stan_model method, I get the same compilation error:

Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! In file included from C:/Users/u0097836/Documents/R/win-library/3.5/rstan/include/rstan/rstaninc.hpp:3:0,
                 from file24ec1884293d.cpp:180123:
C:/Users/u0097836/Documents/R/win-library/3.5/rstan/include/rstan/stan_fit.hpp: In instantiation of 'SEXPREC* rstan::stan_fit<Model, RNG_t>::standalone_gqs(SEXP, SEXP) [with Model = model24ec2e3f1ba3_fd8303e7fa7d239a6d543221dd77fb1a_namespace::model24ec2e3f1ba3_fd8303e7fa7d239a6d543221dd77fb1a; RNG_t = boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014u, 0u, 2147483563u>, boost::random::linear_congruential_engine<unsigned int, 40692u, 0u, 2147483399u> >; SEXP = SEXPREC*]':
file24ec1884293d.cpp:180164:0:   required from here
C:/Users/u0097836/Documents/R/win-library/3.5/rstan/include/rstan/stan_fit.hpp:1222:9: warning: variable 'ret' set but not used [-Wunused-but-set-variable]
     int ret;
         ^
file24ec1884293d.c
In addition: Warning message:
In system(cmd, intern = !verbose) :
  running command 'C:/Users/u0097836/DOCUME~1/R/R-35~1.1/bin/x64/R CMD SHLIB file24ec1884293d.cpp 2> file24ec1884293d.cpp.err.txt' had status 1
Error in sink(type = "output") : invalid connection

This is the code I run for the model estimation:

stanmodel <- stan_model(model_code = make_stancode(formula = value ~ Version.x * variable + (ParticipantID|Version.x) + (ParticipantID|variable), 
+                                                    data = OCSLong, family = binomial(link = "logit"), verbose = T))

I tried using the solutions discussed here, but it was unclear what I needed to do. I tried changing the Makevars file that I could find in my R folders in the RcppArmadillo subfolder according to what was suggested in the discussion here.

This is the content of the Makevars file:

## With R 3.1.0 or later, you can uncomment the following line to tell R to 
## enable compilation with C++11 (where available)
##
## Also, OpenMP support in Armadillo prefers C++11 support. However, for wider
## availability of the package we do not yet enforce this here.  It is however
## recommended for client packages to set it.
##
## And with R 3.4.0, and RcppArmadillo 0.7.960.*, we turn C++11 on as OpenMP
## support within Armadillo prefers / requires it
CXX_STD = CXX11

PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) 
PKG_LIBS = $(SHLIB_OPENMP_CFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

I only changed the line just before the last line:

## With R 3.1.0 or later, you can uncomment the following line to tell R to 
## enable compilation with C++11 (where available)
##
## Also, OpenMP support in Armadillo prefers C++11 support. However, for wider
## availability of the package we do not yet enforce this here.  It is however
## recommended for client packages to set it.
##
## And with R 3.4.0, and RcppArmadillo 0.7.960.*, we turn C++11 on as OpenMP
## support within Armadillo prefers / requires it
CXX_STD = CXX11

PKG_CXXFLAGS += -fPIC
PKG_LIBS = $(SHLIB_OPENMP_CFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

This didn’t change anything.

So, how should I solve the issue? Is this issue due to some mismatches in package compatibility that I overlooked?

There should be more to the error message when compiled with verbose = TRUE. Look for the line that has error: (with the colon) rather than merely warnings.

I doublechecked, but I don’t get anything more in the error message.

Can you do

stancode <- 'data {real y_mean;} parameters {real y;} model {y ~ normal(y_mean,1);}'
mod <- stan_model(model_code = stancode, verbose = TRUE)

?

If I run that, this is what is printed to the R console:

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.18.2; Rcpp: 1.0.0; inline: 0.3.14 
 >> setting environment variables: 
PKG_LIBS =  -L"C:/Users/u0097836/Documents/R/win-library/3.5/StanHeaders/libs/x64" -lStanHeaders
PKG_CPPFLAGS =   -I"C:/Users/u0097836/Documents/R/win-library/3.5/Rcpp/include/"  -I"C:/Users/u0097836/Documents/R/win-library/3.5/RcppEigen/include/"  -I"C:/Users/u0097836/Documents/R/win-library/3.5/RcppEigen/include/unsupported"  -I"C:/Users/u0097836/Documents/R/win-library/3.5/BH/include" -I"C:/Users/u0097836/Documents/R/win-library/3.5/StanHeaders/include/src/"  -I"C:/Users/u0097836/Documents/R/win-library/3.5/StanHeaders/include/"  -I"C:/Users/u0097836/Documents/R/win-library/3.5/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS -std=c++1y
 >> Program source :

   1 : 
   2 : // includes from the plugin
   3 : // [[Rcpp::plugins(cpp14)]]
   4 : 
   5 : // user includes
   6 : #define STAN__SERVICES__COMMAND_HPP// Code generated by Stan version 2.18.1
   7 : 
   8 : #include <stan/model/model_header.hpp>
   9 : 
  10 : namespace modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1_namespace {
  11 : 
  12 : using std::istream;
  13 : using std::string;
  14 : using std::stringstream;
  15 : using std::vector;
  16 : using stan::io::dump;
  17 : using stan::math::lgamma;
  18 : using stan::model::prob_grad;
  19 : using namespace stan::math;
  20 : 
  21 : static int current_statement_begin__;
  22 : 
  23 : stan::io::program_reader prog_reader__() {
  24 :     stan::io::program_reader reader;
  25 :     reader.add_event(0, 0, "start", "modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1");
  26 :     reader.add_event(3, 1, "end", "modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1");
  27 :     return reader;
  28 : }
  29 : 
  30 : class modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1 : public prob_grad {
  31 : private:
  32 :     double y_mean;
  33 : public:
  34 :     modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1(stan::io::var_context& context__,
  35 :         std::ostream* pstream__ = 0)
  36 :         : prob_grad(0) {
  37 :         ctor_body(context__, 0, pstream__);
  38 :     }
  39 : 
  40 :     modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1(stan::io::var_context& context__,
  41 :         unsigned int random_seed__,
  42 :         std::ostream* pstream__ = 0)
  43 :         : prob_grad(0) {
  44 :         ctor_body(context__, random_seed__, pstream__);
  45 :     }
  46 : 
  47 :     void ctor_body(stan::io::var_context& context__,
  48 :                    unsigned int random_seed__,
  49 :                    std::ostream* pstream__) {
  50 :         typedef double local_scalar_t__;
  51 : 
  52 :         boost::ecuyer1988 base_rng__ =
  53 :           stan::services::util::create_rng(random_seed__, 0);
  54 :         (void) base_rng__;  // suppress unused var warning
  55 : 
  56 :         current_statement_begin__ = -1;
  57 : 
  58 :         static const char* function__ = "modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1_namespace::modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1";
  59 :         (void) function__;  // dummy to suppress unused var warning
  60 :         size_t pos__;
  61 :         (void) pos__;  // dummy to suppress unused var warning
  62 :         std::vector<int> vals_i__;
  63 :         std::vector<double> vals_r__;
  64 :         local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
  65 :         (void) DUMMY_VAR__;  // suppress unused var warning
  66 : 
  67 :         // initialize member variables
  68 :         try {
  69 :             current_statement_begin__ = 1;
  70 :             context__.validate_dims("data initialization", "y_mean", "double", context__.to_vec());
  71 :             y_mean = double(0);
  72 :             vals_r__ = context__.vals_r("y_mean");
  73 :             pos__ = 0;
  74 :             y_mean = vals_r__[pos__++];
  75 : 
  76 :             // validate, data variables
  77 :             current_statement_begin__ = 1;
  78 :             // initialize data variables
  79 : 
  80 : 
  81 :             // validate transformed data
  82 : 
  83 :             // validate, set parameter ranges
  84 :             num_params_r__ = 0U;
  85 :             param_ranges_i__.clear();
  86 :             current_statement_begin__ = 1;
  87 :             ++num_params_r__;
  88 :         } catch (const std::exception& e) {
  89 :             stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
  90 :             // Next line prevents compiler griping about no return
  91 :             throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
  92 :         }
  93 :     }
  94 : 
  95 :     ~modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1() { }
  96 : 
  97 : 
  98 :     void transform_inits(const stan::io::var_context& context__,
  99 :                          std::vector<int>& params_i__,
 100 :                          std::vector<double>& params_r__,
 101 :                          std::ostream* pstream__) const {
 102 :         stan::io::writer<double> writer__(params_r__,params_i__);
 103 :         size_t pos__;
 104 :         (void) pos__; // dummy call to supress warning
 105 :         std::vector<double> vals_r__;
 106 :         std::vector<int> vals_i__;
 107 : 
 108 :         if (!(context__.contains_r("y")))
 109 :             throw std::runtime_error("variable y missing");
 110 :         vals_r__ = context__.vals_r("y");
 111 :         pos__ = 0U;
 112 :         context__.validate_dims("initialization", "y", "double", context__.to_vec());
 113 :         double y(0);
 114 :         y = vals_r__[pos__++];
 115 :         try {
 116 :             writer__.scalar_unconstrain(y);
 117 :         } catch (const std::exception& e) { 
 118 :             throw std::runtime_error(std::string("Error transforming variable y: ") + e.what());
 119 :         }
 120 : 
 121 :         params_r__ = writer__.data_r();
 122 :         params_i__ = writer__.data_i();
 123 :     }
 124 : 
 125 :     void transform_inits(const stan::io::var_context& context,
 126 :                          Eigen::Matrix<double,Eigen::Dynamic,1>& params_r,
 127 :                          std::ostream* pstream__) const {
 128 :       std::vector<double> params_r_vec;
 129 :       std::vector<int> params_i_vec;
 130 :       transform_inits(context, params_i_vec, params_r_vec, pstream__);
 131 :       params_r.resize(params_r_vec.size());
 132 :       for (int i = 0; i < params_r.size(); ++i)
 133 :         params_r(i) = params_r_vec[i];
 134 :     }
 135 : 
 136 : 
 137 :     template <bool propto__, bool jacobian__, typename T__>
 138 :     T__ log_prob(vector<T__>& params_r__,
 139 :                  vector<int>& params_i__,
 140 :                  std::ostream* pstream__ = 0) const {
 141 : 
 142 :         typedef T__ local_scalar_t__;
 143 : 
 144 :         local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
 145 :         (void) DUMMY_VAR__;  // suppress unused var warning
 146 : 
 147 :         T__ lp__(0.0);
 148 :         stan::math::accumulator<T__> lp_accum__;
 149 : 
 150 :         try {
 151 :             // model parameters
 152 :             stan::io::reader<local_scalar_t__> in__(params_r__,params_i__);
 153 : 
 154 :             local_scalar_t__ y;
 155 :             (void) y;  // dummy to suppress unused var warning
 156 :             if (jacobian__)
 157 :                 y = in__.scalar_constrain(lp__);
 158 :             else
 159 :                 y = in__.scalar_constrain();
 160 : 
 161 : 
 162 :             // transformed parameters
 163 : 
 164 : 
 165 : 
 166 :             // validate transformed parameters
 167 : 
 168 :             const char* function__ = "validate transformed params";
 169 :             (void) function__;  // dummy to suppress unused var warning
 170 : 
 171 :             // model body
 172 : 
 173 :             current_statement_begin__ = 1;
 174 :             lp_accum__.add(normal_log<propto__>(y, y_mean, 1));
 175 : 
 176 :         } catch (const std::exception& e) {
 177 :             stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
 178 :             // Next line prevents compiler griping about no return
 179 :             throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
 180 :         }
 181 : 
 182 :         lp_accum__.add(lp__);
 183 :         return lp_accum__.sum();
 184 : 
 185 :     } // log_prob()
 186 : 
 187 :     template <bool propto, bool jacobian, typename T_>
 188 :     T_ log_prob(Eigen::Matrix<T_,Eigen::Dynamic,1>& params_r,
 189 :                std::ostream* pstream = 0) const {
 190 :       std::vector<T_> vec_params_r;
 191 :       vec_params_r.reserve(params_r.size());
 192 :       for (int i = 0; i < params_r.size(); ++i)
 193 :         vec_params_r.push_back(params_r(i));
 194 :       std::vector<int> vec_params_i;
 195 :       return log_prob<propto,jacobian,T_>(vec_params_r, vec_params_i, pstream);
 196 :     }
 197 : 
 198 : 
 199 :     void get_param_names(std::vector<std::string>& names__) const {
 200 :         names__.resize(0);
 201 :         names__.push_back("y");
 202 :     }
 203 : 
 204 : 
 205 :     void get_dims(std::vector<std::vector<size_t> >& dimss__) const {
 206 :         dimss__.resize(0);
 207 :         std::vector<size_t> dims__;
 208 :         dims__.resize(0);
 209 :         dimss__.push_back(dims__);
 210 :     }
 211 : 
 212 :     template <typename RNG>
 213 :     void write_array(RNG& base_rng__,
 214 :                      std::vector<double>& params_r__,
 215 :                      std::vector<int>& params_i__,
 216 :                      std::vector<double>& vars__,
 217 :                      bool include_tparams__ = true,
 218 :                      bool include_gqs__ = true,
 219 :                      std::ostream* pstream__ = 0) const {
 220 :         typedef double local_scalar_t__;
 221 : 
 222 :         vars__.resize(0);
 223 :         stan::io::reader<local_scalar_t__> in__(params_r__,params_i__);
 224 :         static const char* function__ = "modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1_namespace::write_array";
 225 :         (void) function__;  // dummy to suppress unused var warning
 226 :         // read-transform, write parameters
 227 :         double y = in__.scalar_constrain();
 228 :         vars__.push_back(y);
 229 : 
 230 :         // declare and define transformed parameters
 231 :         double lp__ = 0.0;
 232 :         (void) lp__;  // dummy to suppress unused var warning
 233 :         stan::math::accumulator<double> lp_accum__;
 234 : 
 235 :         local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
 236 :         (void) DUMMY_VAR__;  // suppress unused var warning
 237 : 
 238 :         try {
 239 : 
 240 : 
 241 : 
 242 :             // validate transformed parameters
 243 : 
 244 :             // write transformed parameters
 245 :             if (include_tparams__) {
 246 :             }
 247 :             if (!include_gqs__) return;
 248 :             // declare and define generated quantities
 249 : 
 250 : 
 251 : 
 252 :             // validate generated quantities
 253 : 
 254 :             // write generated quantities
 255 :         } catch (const std::exception& e) {
 256 :             stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
 257 :             // Next line prevents compiler griping about no return
 258 :             throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
 259 :         }
 260 :     }
 261 : 
 262 :     template <typename RNG>
 263 :     void write_array(RNG& base_rng,
 264 :                      Eigen::Matrix<double,Eigen::Dynamic,1>& params_r,
 265 :                      Eigen::Matrix<double,Eigen::Dynamic,1>& vars,
 266 :                      bool include_tparams = true,
 267 :                      bool include_gqs = true,
 268 :                      std::ostream* pstream = 0) const {
 269 :       std::vector<double> params_r_vec(params_r.size());
 270 :       for (int i = 0; i < params_r.size(); ++i)
 271 :         params_r_vec[i] = params_r(i);
 272 :       std::vector<double> vars_vec;
 273 :       std::vector<int> params_i_vec;
 274 :       write_array(base_rng,params_r_vec,params_i_vec,vars_vec,include_tparams,include_gqs,pstream);
 275 :       vars.resize(vars_vec.size());
 276 :       for (int i = 0; i < vars.size(); ++i)
 277 :         vars(i) = vars_vec[i];
 278 :     }
 279 : 
 280 :     static std::string model_name() {
 281 :         return "modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1";
 282 :     }
 283 : 
 284 : 
 285 :     void constrained_param_names(std::vector<std::string>& param_names__,
 286 :                                  bool include_tparams__ = true,
 287 :                                  bool include_gqs__ = true) const {
 288 :         std::stringstream param_name_stream__;
 289 :         param_name_stream__.str(std::string());
 290 :         param_name_stream__ << "y";
 291 :         param_names__.push_back(param_name_stream__.str());
 292 : 
 293 :         if (!include_gqs__ && !include_tparams__) return;
 294 : 
 295 :         if (include_tparams__) {
 296 :         }
 297 : 
 298 : 
 299 :         if (!include_gqs__) return;
 300 :     }
 301 : 
 302 : 
 303 :     void unconstrained_param_names(std::vector<std::string>& param_names__,
 304 :                                    bool include_tparams__ = true,
 305 :                                    bool include_gqs__ = true) const {
 306 :         std::stringstream param_name_stream__;
 307 :         param_name_stream__.str(std::string());
 308 :         param_name_stream__ << "y";
 309 :         param_names__.push_back(param_name_stream__.str());
 310 : 
 311 :         if (!include_gqs__ && !include_tparams__) return;
 312 : 
 313 :         if (include_tparams__) {
 314 :         }
 315 : 
 316 : 
 317 :         if (!include_gqs__) return;
 318 :     }
 319 : 
 320 : }; // model
 321 : 
 322 : }
 323 : 
 324 : typedef modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1_namespace::modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1 stan_model;
 325 : 
 326 : #include <rstan/rstaninc.hpp>
 327 : /**
 328 :  * Define Rcpp Module to expose stan_fit's functions to R.
 329 :  */
 330 : RCPP_MODULE(stan_fit4modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1_mod){
 331 :   Rcpp::class_<rstan::stan_fit<modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1_namespace::modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1,
 332 :                boost::random::ecuyer1988> >("stan_fit4modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1")
 333 :     // .constructor<Rcpp::List>()
 334 :     .constructor<SEXP, SEXP, SEXP>()
 335 :     // .constructor<SEXP, SEXP>()
 336 :     .method("call_sampler",
 337 :             &rstan::stan_fit<modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1_namespace::modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::call_sampler)
 338 :     .method("param_names",
 339 :             &rstan::stan_fit<modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1_namespace::modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::param_names)
 340 :     .method("param_names_oi",
 341 :             &rstan::stan_fit<modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1_namespace::modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::param_names_oi)
 342 :     .method("param_fnames_oi",
 343 :             &rstan::stan_fit<modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1_namespace::modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::param_fnames_oi)
 344 :     .method("param_dims",
 345 :             &rstan::stan_fit<modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1_namespace::modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::param_dims)
 346 :     .method("param_dims_oi",
 347 :             &rstan::stan_fit<modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1_namespace::modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::param_dims_oi)
 348 :     .method("update_param_oi",
 349 :             &rstan::stan_fit<modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1_namespace::modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::update_param_oi)
 350 :     .method("param_oi_tidx",
 351 :             &rstan::stan_fit<modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1_namespace::modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::param_oi_tidx)
 352 :     .method("grad_log_prob",
 353 :             &rstan::stan_fit<modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1_namespace::modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::grad_log_prob)
 354 :     .method("log_prob",
 355 :             &rstan::stan_fit<modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1_namespace::modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::log_prob)
 356 :     .method("unconstrain_pars",
 357 :             &rstan::stan_fit<modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1_namespace::modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::unconstrain_pars)
 358 :     .method("constrain_pars",
 359 :             &rstan::stan_fit<modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1_namespace::modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::constrain_pars)
 360 :     .method("num_pars_unconstrained",
 361 :             &rstan::stan_fit<modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1_namespace::modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::num_pars_unconstrained)
 362 :     .method("unconstrained_param_names",
 363 :             &rstan::stan_fit<modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1_namespace::modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::unconstrained_param_names)
 364 :     .method("constrained_param_names",
 365 :             &rstan::stan_fit<modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1_namespace::modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::constrained_param_names)
 366 :     .method("standalone_gqs",
 367 :             &rstan::stan_fit<modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1_namespace::modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::standalone_gqs)
 368 :   ;
 369 : }
 370 : 
 371 : // declarations
 372 : extern "C" {
 373 : SEXP filebc02bb13dc0( ) ;
 374 : }
 375 : 
 376 : // definition
 377 : 
 378 : SEXP filebc02bb13dc0(  ){
 379 :  return Rcpp::wrap("73fc79f8b1915e8208c736914c86d1a1");
 380 : }
 381 : 
 382 : 
Compilation argument:
 C:/Users/u0097836/DOCUME~1/R/R-35~1.1/bin/x64/R CMD SHLIB filebc02bb13dc0.cpp 2> filebc02bb13dc0.cpp.err.txt 
C:/RBuildTools/3.4/mingw_64/bin/g++  -std=gnu++11 -I"C:/Users/u0097836/DOCUME~1/R/R-35~1.1/include" -DNDEBUG   -I"C:/Users/u0097836/Documents/R/win-library/3.5/Rcpp/include/"  -I"C:/Users/u0097836/Documents/R/win-library/3.5/RcppEigen/include/"  -I"C:/Users/u0097836/Documents/R/win-library/3.5/RcppEigen/include/unsupported"  -I"C:/Users/u0097836/Documents/R/win-library/3.5/BH/include" -I"C:/Users/u0097836/Documents/R/win-library/3.5/StanHeaders/include/src/"  -I"C:/Users/u0097836/Documents/R/win-library/3.5/StanHeaders/include/"  -I"C:/Users/u0097836/Documents/R/win-library/3.5/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS -std=c++1y    -march=core2     -O2 -Wall  -mtune=generic -c filebc02bb13dc0.cpp -o filebc02bb13dc0.o
C:/RBuildTools/3.4/mingw_64/bin/g++ -shared -s -static-libgcc -o filebc02bb13dc0.dll tmp.def filebc02bb13dc0.o -LC:/Users/u0097836/Documents/R/win-library/3.5/StanHeaders/libs/x64 -lStanHeaders -LC:/Users/u0097836/DOCUME~1/R/R-35~1.1/bin/x64 -lR
In file included from C:/Users/u0097836/Documents/R/win-library/3.5/rstan/include/rstan/rstaninc.hpp:3:0,
                 from filebc02bb13dc0.cpp:326:
C:/Users/u0097836/Documents/R/win-library/3.5/rstan/include/rstan/stan_fit.hpp: In instantiation of 'SEXPREC* rstan::stan_fit<Model, RNG_t>::standalone_gqs(SEXP, SEXP) [with Model = modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1_namespace::modelbc07de72a6_73fc79f8b1915e8208c736914c86d1a1; RNG_t = boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014u, 0u, 2147483563u>, boost::random::linear_congruential_engine<unsigned int, 40692u, 0u, 2147483399u> >; SEXP = SEXPREC*]':
filebc02bb13dc0.cpp:367:0:   required from here
C:/Users/u0097836/Documents/R/win-library/3.5/rstan/include/rstan/stan_fit.hpp:1222:9: warning: variable 'ret' set but not used [-Wunused-but-set-variable]
     int ret;
         ^
In file included from C:/Users/u0097836/Documents/R/win-library/3.5/StanHeaders/include/stan/math/rev/core.hpp:44:0,
                 from C:/Users/u0097836/Documents/R/win-library/3.5/StanHeaders/include/stan/math/rev/mat.hpp:4,
                 from C:/Users/u0097836/Documents/R/win-library/3.5/StanHeaders/include/stan/math.hpp:4,
                 from C:/Users/u0097836/Documents/R/win-library/3.5/StanHeaders/include/src/stan/model/model_header.hpp:4,
                 from filebc02bb13dc0.cpp:8:
C:/Users/u0097836/Documents/R/win-library/3.5/StanHeaders/include/stan/math/rev/core/set_zero_all_adjoints.hpp:14:13: warning: 'void stan::math::set_zero_all_adjoints()' defined but not used [-Wunused-function]
 static void set_zero_all_adjoints() {
             ^

And there is no mod object created?

The mod object was created.

Then there wasn’t an error. You can do sampling(mod) on it. So, if the original model is not compiling, then it is probably some bug in how the C++ was generated. Can you post OCSLong?

OCSLong.csv (93.7 KB)

Dear @bgoodri,

I found the mistake that I made! I flipped around the random effects in my model formula. So, I should have written version|ParticipantID rather than ParticipantID|version.

Kind regards and my apologies!
Hanne