Compile issue for RStan

Compilation argument:
C:/PROGRA~1/R/R-36~1.0/bin/x64/R CMD SHLIB file4b065d86567.cpp 2> file4b065d86567.cpp.err.txt
C:/RBuildTools/3.5/mingw_64/bin/g++ -std=gnu++11 -I"C:/PROGRA~1/R/R-36~1.0/include" -DNDEBUG -I"\domain.internal/dfs/Home/chzhang/My Documents/R/win-library/3.6/Rcpp/include/" -I"C:/Users/chzhang/Documents/R/win-library/3.6/RcppEigen/include/" -I"C:/Users/chzhang/Documents/R/win-library/3.6/RcppEigen/include/unsupported" -I"C:/Users/chzhang/Documents/R/win-library/3.6/BH/include" -I"C:/Users/chzhang/Documents/R/win-library/3.6/StanHeaders/include/src/" -I"C:/Users/chzhang/Documents/R/win-library/3.6/StanHeaders/include/" -I"C:/Users/chzhang/Documents/R/win-library/3.6/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -std=c++1y -march=native -O3 -march=native -mtune=native -c file4b065d86567.cpp -o file4b065d86567.o
In file included from C:/Users/chzhang/Documents/R/win-library/3.6/rstan/include/rstan/stan_fit.hpp:18:0,
from C:/Users/chzhang/Documents/R/win-library/3.6/rstan/include/rstan/rstaninc.hpp:3,
from file4b065d86567.cpp:478:
C:/Users/chzhang/Documents/R/win-library/3.6/rstan/include/rstan/io/rlist_ref_var_context.hpp:16:18: fatal error: Rcpp.h: No such file or directory
#include <Rcpp.h>
^
compilation terminated.
make: *** [C:/PROGRA~1/R/R-36~1.0/etc/x64/Makeconf:215: file4b065d86567.o] Error 1

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: // user includes
6: #define STAN__SERVICES__COMMAND_HPP// Code generated by Stan version 2.19.1
7:
8: #include <stan/model/model_header.hpp>
9:
10: namespace model4b029fc1793_8schools_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”, “model4b029fc1793_8schools”);
26: reader.add_event(20, 18, “end”, “model4b029fc1793_8schools”);
27: return reader;
28: }
29:
30: class model4b029fc1793_8schools : public prob_grad {
31: private:
32: int J;
33: std::vector y;
34: std::vector sigma;
35: public:
36: model4b029fc1793_8schools(stan::io::var_context& context__,
37: std::ostream* pstream__ = 0)
38: : prob_grad(0) {
39: ctor_body(context__, 0, pstream__);
40: }
41:
42: model4b029fc1793_8schools(stan::io::var_context& context__,
43: unsigned int random_seed__,
44: std::ostream* pstream__ = 0)
45: : prob_grad(0) {
46: ctor_body(context__, random_seed__, pstream__);
47: }
48:
49: void ctor_body(stan::io::var_context& context__,
50: unsigned int random_seed__,
51: std::ostream* pstream__) {
52: typedef double local_scalar_t__;
53:
54: boost::ecuyer1988 base_rng__ =
55: stan::services::util::create_rng(random_seed__, 0);
56: (void) base_rng__; // suppress unused var warning
57:
58: current_statement_begin__ = -1;
59:
60: static const char* function__ = “model4b029fc1793_8schools_namespace::model4b029fc1793_8schools”;
61: (void) function__; // dummy to suppress unused var warning
62: size_t pos__;
63: (void) pos__; // dummy to suppress unused var warning
64: std::vector vals_i__;
65: std::vector vals_r__;
66: local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN());
67: (void) DUMMY_VAR__; // suppress unused var warning
68:
69: try {
70: // initialize data block variables from context__
71: current_statement_begin__ = 3;
72: context__.validate_dims(“data initialization”, “J”, “int”, context__.to_vec());
73: J = int(0);
74: vals_i__ = context__.vals_i(“J”);
75: pos__ = 0;
76: J = vals_i__[pos__++];
77: check_greater_or_equal(function__, “J”, J, 0);
78:
79: current_statement_begin__ = 4;
80: validate_non_negative_index(“y”, “J”, J);
81: context__.validate_dims(“data initialization”, “y”, “double”, context__.to_vec(J));
82: y = std::vector(J, double(0));
83: vals_r__ = context__.vals_r(“y”);
84: pos__ = 0;
85: size_t y_k_0_max__ = J;
86: for (size_t k_0__ = 0; k_0__ < y_k_0_max__; ++k_0__) {
87: y[k_0__] = vals_r__[pos__++];
88: }
89:
90: current_statement_begin__ = 5;
91: validate_non_negative_index(“sigma”, “J”, J);
92: context__.validate_dims(“data initialization”, “sigma”, “double”, context__.to_vec(J));
93: sigma = std::vector(J, double(0));
94: vals_r__ = context__.vals_r(“sigma”);
95: pos__ = 0;
96: size_t sigma_k_0_max__ = J;
97: for (size_t k_0__ = 0; k_0__ < sigma_k_0_max__; ++k_0__) {
98: sigma[k_0__] = vals_r__[pos__++];
99: }
100: size_t sigma_i_0_max__ = J;
101: for (size_t i_0__ = 0; i_0__ < sigma_i_0_max__; ++i_0__) {
102: check_greater_or_equal(function__, “sigma[i_0__]”, sigma[i_0__], 0);
103: }
104:
105:
106: // initialize transformed data variables
107: // execute transformed data statements
108:
109: // validate transformed data
110:
111: // validate, set parameter ranges
112: num_params_r__ = 0U;
113: param_ranges_i__.clear();
114: current_statement_begin__ = 8;
115: num_params_r__ += 1;
116: current_statement_begin__ = 9;
117: num_params_r__ += 1;
118: current_statement_begin__ = 10;
119: validate_non_negative_index(“eta”, “J”, J);
120: num_params_r__ += J;
121: } catch (const std::exception& e) {
122: stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
123: // Next line prevents compiler griping about no return
124: throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ");
125: }
126: }
127:
128: ~model4b029fc1793_8schools() { }
129:
130:
131: void transform_inits(const stan::io::var_context& context__,
132: std::vector& params_i__,
133: std::vector& params_r__,
134: std::ostream
pstream__) const {
135: typedef double local_scalar_t__;
136: stan::io::writer writer__(params_r__, params_i__);
137: size_t pos__;
138: (void) pos__; // dummy call to supress warning
139: std::vector vals_r__;
140: std::vector vals_i__;
141:
142: current_statement_begin__ = 8;
143: if (!(context__.contains_r(“mu”)))
144: stan::lang::rethrow_located(std::runtime_error(std::string(“Variable mu missing”)), current_statement_begin__, prog_reader__());
145: vals_r__ = context__.vals_r(“mu”);
146: pos__ = 0U;
147: context__.validate_dims(“parameter initialization”, “mu”, “double”, context__.to_vec());
148: double mu(0);
149: mu = vals_r__[pos__++];
150: try {
151: writer__.scalar_unconstrain(mu);
152: } catch (const std::exception& e) {
153: stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable mu: ") + e.what()), current_statement_begin__, prog_reader__());
154: }
155:
156: current_statement_begin__ = 9;
157: if (!(context__.contains_r(“tau”)))
158: stan::lang::rethrow_located(std::runtime_error(std::string(“Variable tau missing”)), current_statement_begin__, prog_reader__());
159: vals_r__ = context__.vals_r(“tau”);
160: pos__ = 0U;
161: context__.validate_dims(“parameter initialization”, “tau”, “double”, context__.to_vec());
162: double tau(0);
163: tau = vals_r__[pos__++];
164: try {
165: writer__.scalar_lb_unconstrain(0, tau);
166: } catch (const std::exception& e) {
167: stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable tau: ") + e.what()), current_statement_begin__, prog_reader__());
168: }
169:
170: current_statement_begin__ = 10;
171: if (!(context__.contains_r(“eta”)))
172: stan::lang::rethrow_located(std::runtime_error(std::string(“Variable eta missing”)), current_statement_begin__, prog_reader__());
173: vals_r__ = context__.vals_r(“eta”);
174: pos__ = 0U;
175: validate_non_negative_index(“eta”, “J”, J);
176: context__.validate_dims(“parameter initialization”, “eta”, “vector_d”, context__.to_vec(J));
177: Eigen::Matrix<double, Eigen::Dynamic, 1> eta(J);
178: size_t eta_j_1_max__ = J;
179: for (size_t j_1__ = 0; j_1__ < eta_j_1_max__; ++j_1__) {
180: eta(j_1__) = vals_r__[pos__++];
181: }
182: try {
183: writer__.vector_unconstrain(eta);
184: } catch (const std::exception& e) {
185: stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable eta: ") + e.what()), current_statement_begin__, prog_reader__());
186: }
187:
188: params_r__ = writer__.data_r();
189: params_i__ = writer__.data_i();
190: }
191:
192: void transform_inits(const stan::io::var_context& context,
193: Eigen::Matrix<double, Eigen::Dynamic, 1>& params_r,
194: std::ostream
pstream__) const {
195: std::vector params_r_vec;
196: std::vector params_i_vec;
197: transform_inits(context, params_i_vec, params_r_vec, pstream__);
198: params_r.resize(params_r_vec.size());
199: for (int i = 0; i < params_r.size(); ++i)
200: params_r(i) = params_r_vec[i];
201: }
202:
203:
204: template <bool propto__, bool jacobian__, typename T__>
205: T__ log_prob(std::vector<T__>& params_r__,
206: std::vector& params_i__,
207: std::ostream
pstream__ = 0) const {
208:
209: typedef T__ local_scalar_t__;
210:
211: local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN());
212: (void) DUMMY_VAR__; // dummy to suppress unused var warning
213:
214: T__ lp__(0.0);
215: stan::math::accumulator<T__> lp_accum__;
216: try {
217: stan::io::reader<local_scalar_t__> in__(params_r__, params_i__);
218:
219: // model parameters
220: current_statement_begin__ = 8;
221: local_scalar_t__ mu;
222: (void) mu; // dummy to suppress unused var warning
223: if (jacobian__)
224: mu = in__.scalar_constrain(lp__);
225: else
226: mu = in__.scalar_constrain();
227:
228: current_statement_begin__ = 9;
229: local_scalar_t__ tau;
230: (void) tau; // dummy to suppress unused var warning
231: if (jacobian__)
232: tau = in__.scalar_lb_constrain(0, lp__);
233: else
234: tau = in__.scalar_lb_constrain(0);
235:
236: current_statement_begin__ = 10;
237: Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> eta;
238: (void) eta; // dummy to suppress unused var warning
239: if (jacobian__)
240: eta = in__.vector_constrain(J, lp__);
241: else
242: eta = in__.vector_constrain(J);
243:
244: // transformed parameters
245: current_statement_begin__ = 13;
246: validate_non_negative_index(“theta”, “J”, J);
247: Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> theta(J);
248: stan::math::initialize(theta, DUMMY_VAR__);
249: stan::math::fill(theta, DUMMY_VAR__);
250: stan::math::assign(theta,add(mu, multiply(tau, eta)));
251:
252: // validate transformed parameters
253: const char* function__ = “validate transformed params”;
254: (void) function__; // dummy to suppress unused var warning
255:
256: current_statement_begin__ = 13;
257: size_t theta_j_1_max__ = J;
258: for (size_t j_1__ = 0; j_1__ < theta_j_1_max__; ++j_1__) {
259: if (stan::math::is_uninitialized(theta(j_1__))) {
260: std::stringstream msg__;
261: msg__ << “Undefined transformed parameter: theta” << “(” << j_1__ << “)”;
262: stan::lang::rethrow_located(std::runtime_error(std::string(“Error initializing variable theta: “) + msg__.str()), current_statement_begin__, prog_reader__());
263: }
264: }
265:
266: // model body
267:
268: current_statement_begin__ = 16;
269: lp_accum__.add(normal_log(eta, 0, 1));
270: current_statement_begin__ = 17;
271: lp_accum__.add(normal_log(y, theta, sigma));
272:
273: } catch (const std::exception& e) {
274: stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
275: // Next line prevents compiler griping about no return
276: throw std::runtime_error(”*** IF YOU SEE THIS, PLEASE REPORT A BUG ");
277: }
278:
279: lp_accum__.add(lp__);
280: return lp_accum__.sum();
281:
282: } // log_prob()
283:
284: template <bool propto, bool jacobian, typename T_>
285: T_ log_prob(Eigen::Matrix<T_,Eigen::Dynamic,1>& params_r,
286: std::ostream
pstream = 0) const {
287: std::vector<T_> vec_params_r;
288: vec_params_r.reserve(params_r.size());
289: for (int i = 0; i < params_r.size(); ++i)
290: vec_params_r.push_back(params_r(i));
291: std::vector vec_params_i;
292: return log_prob<propto,jacobian,T_>(vec_params_r, vec_params_i, pstream);
293: }
294:
295:
296: void get_param_names(std::vectorstd::string& names__) const {
297: names__.resize(0);
298: names__.push_back(“mu”);
299: names__.push_back(“tau”);
300: names__.push_back(“eta”);
301: names__.push_back(“theta”);
302: }
303:
304:
305: void get_dims(std::vector<std::vector<size_t> >& dimss__) const {
306: dimss__.resize(0);
307: std::vector<size_t> dims__;
308: dims__.resize(0);
309: dimss__.push_back(dims__);
310: dims__.resize(0);
311: dimss__.push_back(dims__);
312: dims__.resize(0);
313: dims__.push_back(J);
314: dimss__.push_back(dims__);
315: dims__.resize(0);
316: dims__.push_back(J);
317: dimss__.push_back(dims__);
318: }
319:
320: template
321: void write_array(RNG& base_rng__,
322: std::vector& params_r__,
323: std::vector& params_i__,
324: std::vector& vars__,
325: bool include_tparams__ = true,
326: bool include_gqs__ = true,
327: std::ostream
pstream__ = 0) const {
328: typedef double local_scalar_t__;
329:
330: vars__.resize(0);
331: stan::io::reader<local_scalar_t__> in__(params_r__, params_i__);
332: static const char
function__ = “model4b029fc1793_8schools_namespace::write_array”;
333: (void) function__; // dummy to suppress unused var warning
334:
335: // read-transform, write parameters
336: double mu = in__.scalar_constrain();
337: vars__.push_back(mu);
338:
339: double tau = in__.scalar_lb_constrain(0);
340: vars__.push_back(tau);
341:
342: Eigen::Matrix<double, Eigen::Dynamic, 1> eta = in__.vector_constrain(J);
343: size_t eta_j_1_max__ = J;
344: for (size_t j_1__ = 0; j_1__ < eta_j_1_max__; ++j_1__) {
345: vars__.push_back(eta(j_1__));
346: }
347:
348: double lp__ = 0.0;
349: (void) lp__; // dummy to suppress unused var warning
350: stan::math::accumulator lp_accum__;
351:
352: local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN());
353: (void) DUMMY_VAR__; // suppress unused var warning
354:
355: if (!include_tparams__ && !include_gqs__) return;
356:
357: try {
358: // declare and define transformed parameters
359: current_statement_begin__ = 13;
360: validate_non_negative_index(“theta”, “J”, J);
361: Eigen::Matrix<double, Eigen::Dynamic, 1> theta(J);
362: stan::math::initialize(theta, DUMMY_VAR__);
363: stan::math::fill(theta, DUMMY_VAR__);
364: stan::math::assign(theta,add(mu, multiply(tau, eta)));
365:
366: if (!include_gqs__ && !include_tparams__) return;
367: // validate transformed parameters
368: const char* function__ = “validate transformed params”;
369: (void) function__; // dummy to suppress unused var warning
370:
371: // write transformed parameters
372: if (include_tparams__) {
373: size_t theta_j_1_max__ = J;
374: for (size_t j_1__ = 0; j_1__ < theta_j_1_max__; ++j_1__) {
375: vars__.push_back(theta(j_1__));
376: }
377: }
378: if (!include_gqs__) return;
379: } catch (const std::exception& e) {
380: stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
381: // Next line prevents compiler griping about no return
382: throw std::runtime_error(”*** IF YOU SEE THIS, PLEASE REPORT A BUG ");
383: }
384: }
385:
386: template
387: void write_array(RNG& base_rng,
388: Eigen::Matrix<double,Eigen::Dynamic,1>& params_r,
389: Eigen::Matrix<double,Eigen::Dynamic,1>& vars,
390: bool include_tparams = true,
391: bool include_gqs = true,
392: std::ostream
pstream = 0) const {
393: std::vector params_r_vec(params_r.size());
394: for (int i = 0; i < params_r.size(); ++i)
395: params_r_vec[i] = params_r(i);
396: std::vector vars_vec;
397: std::vector params_i_vec;
398: write_array(base_rng, params_r_vec, params_i_vec, vars_vec, include_tparams, include_gqs, pstream);
399: vars.resize(vars_vec.size());
400: for (int i = 0; i < vars.size(); ++i)
401: vars(i) = vars_vec[i];
402: }
403:
404: static std::string model_name() {
405: return “model4b029fc1793_8schools”;
406: }
407:
408:
409: void constrained_param_names(std::vectorstd::string& param_names__,
410: bool include_tparams__ = true,
411: bool include_gqs__ = true) const {
412: std::stringstream param_name_stream__;
413: param_name_stream__.str(std::string());
414: param_name_stream__ << “mu”;
415: param_names__.push_back(param_name_stream__.str());
416: param_name_stream__.str(std::string());
417: param_name_stream__ << “tau”;
418: param_names__.push_back(param_name_stream__.str());
419: size_t eta_j_1_max__ = J;
420: for (size_t j_1__ = 0; j_1__ < eta_j_1_max__; ++j_1__) {
421: param_name_stream__.str(std::string());
422: param_name_stream__ << “eta” << ‘.’ << j_1__ + 1;
423: param_names__.push_back(param_name_stream__.str());
424: }
425:
426: if (!include_gqs__ && !include_tparams__) return;
427:
428: if (include_tparams__) {
429: size_t theta_j_1_max__ = J;
430: for (size_t j_1__ = 0; j_1__ < theta_j_1_max__; ++j_1__) {
431: param_name_stream__.str(std::string());
432: param_name_stream__ << “theta” << ‘.’ << j_1__ + 1;
433: param_names__.push_back(param_name_stream__.str());
434: }
435: }
436:
437: if (!include_gqs__) return;
438: }
439:
440:
441: void unconstrained_param_names(std::vectorstd::string& param_names__,
442: bool include_tparams__ = true,
443: bool include_gqs__ = true) const {
444: std::stringstream param_name_stream__;
445: param_name_stream__.str(std::string());
446: param_name_stream__ << “mu”;
447: param_names__.push_back(param_name_stream__.str());
448: param_name_stream__.str(std::string());
449: param_name_stream__ << “tau”;
450: param_names__.push_back(param_name_stream__.str());
451: size_t eta_j_1_max__ = J;
452: for (size_t j_1__ = 0; j_1__ < eta_j_1_max__; ++j_1__) {
453: param_name_stream__.str(std::string());
454: param_name_stream__ << “eta” << ‘.’ << j_1__ + 1;
455: param_names__.push_back(param_name_stream__.str());
456: }
457:
458: if (!include_gqs__ && !include_tparams__) return;
459:
460: if (include_tparams__) {
461: size_t theta_j_1_max__ = J;
462: for (size_t j_1__ = 0; j_1__ < theta_j_1_max__; ++j_1__) {
463: param_name_stream__.str(std::string());
464: param_name_stream__ << “theta” << ‘.’ << j_1__ + 1;
465: param_names__.push_back(param_name_stream__.str());
466: }
467: }
468:
469: if (!include_gqs__) return;
470: }
471:
472: }; // model
473:
474: } // namespace
475:
476: typedef model4b029fc1793_8schools_namespace::model4b029fc1793_8schools stan_model;
477:
478: #include <rstan/rstaninc.hpp>
479: /

480: * Define Rcpp Module to expose stan_fit’s functions to R.
481: /
482: RCPP_MODULE(stan_fit4model4b029fc1793_8schools_mod){
483: Rcpp::class_<rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools,
484: boost::random::ecuyer1988> >(“stan_fit4model4b029fc1793_8schools”)
485: // .constructorRcpp::List()
486: .constructor<SEXP, SEXP, SEXP>()
487: // .constructor<SEXP, SEXP>()
488: .method(“call_sampler”,
489: &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::call_sampler)
490: .method(“param_names”,
491: &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::param_names)
492: .method(“param_names_oi”,
493: &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::param_names_oi)
494: .method(“param_fnames_oi”,
495: &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::param_fnames_oi)
496: .method(“param_dims”,
497: &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::param_dims)
498: .method(“param_dims_oi”,
499: &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::param_dims_oi)
500: .method(“update_param_oi”,
501: &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::update_param_oi)
502: .method(“param_oi_tidx”,
503: &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::param_oi_tidx)
504: .method(“grad_log_prob”,
505: &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::grad_log_prob)
506: .method(“log_prob”,
507: &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::log_prob)
508: .method(“unconstrain_pars”,
509: &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::unconstrain_pars)
510: .method(“constrain_pars”,
511: &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::constrain_pars)
512: .method(“num_pars_unconstrained”,
513: &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::num_pars_unconstrained)
514: .method(“unconstrained_param_names”,
515: &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::unconstrained_param_names)
516: .method(“constrained_param_names”,
517: &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::constrained_param_names)
518: /

519: .method(“standalone_gqs”,
520: &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::standalone_gqs)
521: */
522: ;
523: }
524:
525: // declarations
526: extern “C” {
527: SEXP file4b065d86567( ) ;
528: }
529:
530: // definition
531:
532: SEXP file4b065d86567( ){
533: return Rcpp::wrap(“8schools”);
534: }
535:
536:
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! In file included from C:/Users/chzhang/Documents/R/win-library/3.6/rstan/include/rstan/stan_fit.hpp:18:0,
from C:/Users/chzhang/Documents/R/win-library/3.6/rstan/include/rstan/rstaninc.hpp:3,
from file4b065d86567.cpp:478:
C:/Users/chzhang/Documents/R/win-library/3.6/rstan/include/rstan/io/rlist_ref_var_context.hpp:16:18: fatal error: Rcpp.h: No such file or directory
#include <Rcpp.h>
^
compilation terminated.
make: *** [C:/PROGRA~1/R/R-36~1.0/etc/x64/Makeconf:215: file4b065d86567.o] Error 1

Yes, it is looking for Rcpp headers at \domain.internal/dfs/Home/chzhang/My Documents/R/win-library/3.6/Rcpp/include/ and RcppEigen and other headers at
C:/Users/chzhang/Documents/R/win-library/3.6/.... I don’t know why that is but it will mess up the compilation.

Hi Ben,

Just let you know, I ask the IT guys to install everything in local mode. i.e., the installation is identical to that at own laptop. Then, transfer to company administration mode. It works well this afternoon.

However, tonight, when I restart Rstudio, an error occurs again…

I also did a quick search, and multiply a*b has been specify as a * b as well.

Hello,
I have the same error as in the original post. I also have rstan working on my personal laptop but not on my school PC (on which R is installed in the C drive and most R packages are in a different drive)

Here is the error:

fit ← stan(file = ‘8schools.stan’, data = schools_dat, verbose=)
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! file1d545b758b0.cpp:8:39: fatal error: stan/model/model_header.hpp: No such file or directory
#include <stan/model/model_header.hpp>
^
compilation terminated.
make: *** [C:/PROGRA~1/R/R-36~1.0/etc/x64/Makeconf:215: file1d545b758b0.o] Error 1
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘C:/PROGRA~1/R/R-36~1.0/bin/x64/R CMD SHLIB file1d545b758b0.cpp 2> file1d545b758b0.cpp.err.txt’ had status 1
Error in sink(type = “output”) : invalid connection

Here is my session info:
sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 16299)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252 LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C LC_TIME=English_United Kingdom.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] rstan_2.18.2 StanHeaders_2.18.1-10 ggplot2_3.2.0

loaded via a namespace (and not attached):
[1] Rcpp_1.0.1 rstudioapi_0.10 magrittr_1.5 tidyselect_0.2.5 munsell_0.5.0 colorspace_1.4-1
[7] R6_2.4.0 rlang_0.4.0 dplyr_0.8.2 tools_3.6.0 pkgbuild_1.0.3 parallel_3.6.0
[13] grid_3.6.0 packrat_0.5.0 gtable_0.3.0 loo_2.1.0 cli_1.1.0 withr_2.1.2
[19] matrixStats_0.54.0 lazyeval_0.2.2 assertthat_0.2.1 tibble_2.1.3 crayon_1.3.4 processx_3.4.0
[25] gridExtra_2.3 callr_3.3.0 purrr_0.3.2 ps_1.3.0 inline_0.3.15 glue_1.3.1
[31] compiler_3.6.0 pillar_1.4.2 prettyunits_1.0.2 scales_1.0.0 stats4_3.6.0 pkgconfig_2.0.2

Thank you for any help on this!!

Just do

install.packages("https://win-builder.r-project.org/rTkumr03G8UM/rstan_2.19.1.zip", repos = NULL)

and then check on CRAN for 2.19.2 binaries in a day or two.

Hi Ben and JC718,

Thanks for your sharing and solutions.

Finally, I ask my company IT guys to install everything at local mode, and it works well.

Then, back to administration mode, the key thing is to delete .Rdata file saved in the remote/shared folder. Instead, you can save your result with a different name to a different location.

Then, it works well.

Chuanwu

Is there any solution to this other than installing everything on a local drive? I’ve tried reinstalling rstan and StanHeaders today and get the same error. Here’s the section causing the error -

Compilation argument:
C:/PROGRA~1/R/R-36~1.0/bin/x64/R CMD SHLIB file2dac16f01062.cpp 2> file2dac16f01062.cpp.err.txt
c:/Rtools/mingw_64/bin/g++ -std=gnu++11 -I"C:/PROGRA~1/R/R-36~1.0/include" -DNDEBUG -I"\icnas1.cc.ic.ac.uk/jc718/R/win-library/3.6/Rcpp/include/" -I"\icnas1.cc.ic.ac.uk/jc718/R/win-library/3.6/RcppEigen/include/" -I"\icnas1.cc.ic.ac.uk/jc718/R/win-library/3.6/RcppEigen/include/unsupported" -I"\icnas1.cc.ic.ac.uk/jc718/R/win-library/3.6/BH/include" -I"\icnas1.cc.ic.ac.uk/jc718/R/win-library/3.6/StanHeaders/include/src/" -I"\icnas1.cc.ic.ac.uk/jc718/R/win-library/3.6/StanHeaders/include/" -I"\icnas1.cc.ic.ac.uk/jc718/R/win-library/3.6/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -std=c++1y -march=core2 -O3 -march=native -mtune=native -c file2dac16f01062.cpp -o file2dac16f01062.o
file2dac16f01062.cpp:8:39: fatal error: stan/model/model_header.hpp: No such file or directory
#include <stan/model/model_header.hpp>
^
compilation terminated.
make: *** [C:/PROGRA~1/R/R-36~1.0/etc/x64/Makeconf:215: file2dac16f01062.o] Error 1

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

Thanks!

I wonder if g++ even recognizes ""\icnas1.cc.ic.ac.uk/jc718/R/win-library/3.6/Rcpp/include/" as a valid path, especially given the backslash at the beginning of the path.

I suggest creating a C++ file named test.cpp with the following contents:

#include <Rcpp.h>

int main() {
   return 0;
}

Then, try to compile it with the following command:

g++ -I"\icnas1.cc.ic.ac.uk/jc718/R/win-library/3.6/Rcpp/include/" test.cpp

Hopefully, whatever error messages you get (or lack of same) should let you know if g++ can even find “Rcpp.h”.

Looks like that is the problem! Here’s the error I get:

g++ -I"\icnas1.cc.ic.ac.uk/jc718/R/win-library/3.6/Rcpp/include/" test.cpp
Error: ‘\i’ is an unrecognized escape in character string starting “”\i"

So how can I fix it? Thanks!

See what happens if you have “\\i” instead of “\i”.

ETA: I’m not sure if that will work, but I figured it’s worth trying out.

Here’s the error now:

g++ -I"\icnas1.cc.ic.ac.uk/jc718/R/win-library/3.6/Rcpp/include/" test.cpp
Error: unexpected string constant in “g++ -I”\icnas1.cc.ic.ac.uk/jc718/R/win-library/3.6/Rcpp/include/“”

Judging from a StackOverflow question, replacing “\i” with "//i might work. Try it and see what you get.

Same error as before:

g++ -I"//icnas1.cc.ic.ac.uk/jc718/R/win-library/3.6/Rcpp/include/" test.cpp
Error: unexpected string constant in “g++ -I”//icnas1.cc.ic.ac.uk/jc718/R/win-library/3.6/Rcpp/include/“”

thanks!

Wait a minute. The error “Error: unexpected string constant” is an R error message. You should have been typing the commands that I gave you at a terminal prompt. They aren’t R commands!

You should be able to get access to a terminal from RStudio, though. Next to the “Console” tab should be a “Terminal” tab. See here for details: https://support.rstudio.com/hc/en-us/articles/115010737148-Using-the-RStudio-Terminal

i need to install partialAR package in R but it shown the following error

Installing package into ‘C:/Users/hemant/AppData/Local/R/win-library/4.2’
(as ‘lib’ is unspecified)

  • installing source package ‘partialAR’ …
    ** using staged installation
    ** libs
    g++ -std=gnu++11 -I"C:/PROGRA~1/R/R-42~1.2/include" -DNDEBUG -I’C:/Users/hemant/AppData/Local/R/win-library/4.2/Rcpp/include’ -I"C:/RBuildTools/4.2/x86_64-w64-mingw32.static.posix/include" -O2 -Wall -mfpmath=sse -msse2 -mstackrealign -c RcppExports.cpp -o RcppExports.o
    g++ -std=gnu++11 -I"C:/PROGRA~1/R/R-42~1.2/include" -DNDEBUG -I’C:/Users/hemant/AppData/Local/R/win-library/4.2/Rcpp/include’ -I"C:/RBuildTools/4.2/x86_64-w64-mingw32.static.posix/include" -O2 -Wall -mfpmath=sse -msse2 -mstackrealign -c cfit.cc -o cfit.o
    cfit.cc: In function ‘double loglik_par_c(Rcpp::NumericVector, double, double, double, double, double)’:
    cfit.cc:171:41: error: ‘PI’ was not declared in this scope
    171 | double nll = (n/2.0)log(tvar * 2.0PI) + esumsq/(2.0*tvar);
    | ^~
    cfit.cc: In function ‘double loglik_par_t_c(Rcpp::NumericVector, double, double, double, double, double, double)’:
    cfit.cc:202:66: error: ‘PI’ was not declared in this scope
    202 | double const_term = n * (lgamma((nu+1.0)0.5) - 0.5log(nu * PI) -
    | ^~
    make: *** [C:/PROGRA~1/R/R-42~1.2/etc/x64/Makeconf:258: cfit.o] Error 1
    ERROR: compilation failed for package ‘partialAR’
  • removing ‘C:/Users/hemant/AppData/Local/R/win-library/4.2/partialAR’
    Warning message:
    In i.p(…) :
    installation of package ‘C:/Users/hemant/AppData/Local/Temp/RtmpKG8NNY/file20cc1b6a198f/partialAR_1.0.12.tar.gz’ had non-zero exit status

please tell me how can i resolve it

This is not an error with Stan or a Stan R package. For installation issues with other R packages you’ll need to contact their developers for help. The partialAR github is here: GitHub - matthewclegg/partialAR: R package for fitting the partially autoregressive model, so you can open an issue there and ask the developer for help