Running examples in 'TiPS-Ex.R' failed
The error most likely occurred in:

> ### Name: build_simulator
> ### Title: Builds a simulator of dynamics of population-model
> ### Aliases: build_simulator
> 
> ### ** Examples
> 
> # Build a simulator for an SIR model
> reactions <- c('S [beta * S * I] -> I',
+                'I [gamma * I] -> R')
>                
> sir.simu <- build_simulator(reactions = reactions)
Building the simulator ...
Compiling the simulator ...

ERROR(s) during compilation: source code errors or compiler configuration errors!
make cmd is
  make -f "C:/msys64/home/tomas/ucrt3/svn/ucrt3/R_PACK~1/rinst/etc/x64/Makeconf" -f "C:/msys64/home/tomas/ucrt3/svn/ucrt3/R_PACK~1/rinst/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="file18a7c14b3309.dll" WIN=64 TCLBIN= OBJECTS="file18a7c14b3309.o"

make would use
Warning message:
In system(paste(cmd, "-n")) : 'make' not found

Program source:
  1: 
  2: // includes from the plugin
  3: 
  4: #include <Rcpp.h>
  5: 
  6: 
  7: #ifndef BEGIN_RCPP
  8: #define BEGIN_RCPP
  9: #endif
 10: 
 11: #ifndef END_RCPP
 12: #define END_RCPP
 13: #endif
 14: 
 15: using namespace Rcpp;
 16: 
 17: // user includes
 18: 
 19:   // [[Rcpp::plugins(cpp11)]]
 20:   #include <Rcpp.h>
 21:   #include <map>
 22:   #include <utility>
 23:   #include <algorithm>
 24:   #include <vector>
 25:   #include <cstdlib>
 26:   #include <chrono>
 27:   #include <sys/time.h>
 28:   #include <random>
 29: 
 30:   using namespace Rcpp;
 31:   using namespace std;
 32: 
 33:   class reactions {
 34:   
 35: private:
 36: 	vector<double> vRates_;
 37: 	long seed_;
 38: 	int nTrials_;
 39: 	double time_ , deltaT_ , beta , gamma , S , I , R  ;
 40: 	NumericVector initialStates_;
 41: 	NumericVector vTimes_;
 42: 	map<string,double> compartments;
 43: 	vector<vector<string> > vFrom;
 44: 	vector<vector<string> > vTo;
 45: 	vector<string> vreactions;
 46: 	vector<double> dfTimes;
 47: 	 vector<double> dfS;
 48: 	 vector<double> dfI;
 49: 	 vector<double> dfR;
 50: 	vector<string> dfreactions;
 51: 	vector<int> dfNrep;
 52: 	std::mt19937 randomGenerator_;
 53: 	vector<NumericVector> parameters_;
 54: 	bool isSwitchingMode_;
 55: 	bool verbose_;
 56: public:
 57: 	
 58:   reactions(List params, NumericVector initialStates, NumericVector times, double deltaT, int nTrials, bool isSwitchingMode, bool verbose) : nTrials_(nTrials), deltaT_(deltaT), isSwitchingMode_(isSwitchingMode){
 59:     verbose_ = verbose;
 60:   for (unsigned i = 0; i < params.size(); i++){
 61:   parameters_.push_back(params[i]);
 62:   }
 63:   initialStates_ = initialStates;
 64:   vTimes_ = times;
 65:   initStructures();
 66:   initRandomSeed();
 67:   randomGenerator_.seed(seed_);
 68:   time_ = vTimes_[0];
 69:   }
 70:   
 71: ~reactions(){}
 72: 
 73:   void initRandomSeed(){
 74:   struct timeval start;
 75:   gettimeofday(&start,NULL);
 76:   seed_ = start.tv_usec;
 77:   randomGenerator_.seed(seed_); 
 78:   }
 79:   
 80: void initStructures(){
 81: 	
 82: 	compartments["S"] = initialStates_["S"];
 83: 	compartments["I"] = initialStates_["I"];
 84: 	compartments["R"] = initialStates_["R"];
 85: 	vector<string> indiv(0);
 86: 	vRates_.assign(2,0);
 87: 	vFrom.assign(2,indiv);
 88: 	vTo.assign(2,indiv);
 89: 	
 90: 	vFrom[0].push_back("S");
 91: 	vFrom[1].push_back("I");
 92: 	
 93: 	vTo[0].push_back("I");
 94: 	vTo[1].push_back("R");
 95: 	vreactions.assign(2,"");
 96: 	vreactions[0]="S [beta * S * I] -> I";
 97: 	vreactions[1]="I [gamma * I] -> R";
 98: 	updateCompartments();
 99: 	dfreactions.assign(1,"init");
100: 	dfNrep.assign(1,1);
101: }
102: void initParams(unsigned timePart){
103: 	
104: 	beta = parameters_[timePart]["beta"];
105: 	gamma = parameters_[timePart]["gamma"];
106: 	updateRates();
107: }
108: void reInitializeDataFrame(){
109: 	dfreactions.clear();
110: dfNrep.clear();
111: dfTimes.clear();
112: dfS.clear();
113: dfI.clear();
114: dfR.clear();
115: time_ = vTimes_[0];
116: dfreactions.assign(1,"init");
117: dfNrep.assign(1,1);
118: 
119: 	compartments["S"] = initialStates_["S"];
120: 	compartments["I"] = initialStates_["I"];
121: 	compartments["R"] = initialStates_["R"];
122: updateCompartments();
123: initParams(0);
124: updateDataFrameOutput();
125: }
126: void updateRates(){
127: 
128: 	vRates_[0]=beta * S * I;
129: 	vRates_[1]=gamma * I;
130: }
131: void updateCompartments(){
132: 
133: 	S = compartments["S"];
134: 	I = compartments["I"];
135: 	R = compartments["R"];
136: }
137: 
138:   double computeTotalRate(){
139:     double sum = 0;
140:     for(vector<double>::iterator it=vRates_.begin();it!=vRates_.end();it++){
141:       sum += *it;
142:     }
143:     return sum;
144:   }
145:   
146: 
147:   int whichReaction(const double& totalRate){
148:     double r = (double)rand() / RAND_MAX ;
149:     double sum = 0.0 ;
150:     int indx = 0;
151:     vector<double>::iterator it;
152:     for(it=vRates_.begin() ; it!=vRates_.end() && sum<(r*totalRate) ; ++it, indx++){
153:       sum += *it;
154:     }
155:     indx--;
156:     return indx;
157:   }
158:   
159: 
160:   bool isFromSizeEnough(int reac, int nbReac){
161:     vector<bool> isEnough;
162:     int nbFrom = 0;
163:     string indiv;
164:     for (unsigned i = 0; i < vFrom[reac].size(); i++){
165:       if(find(vTo[reac].begin(),vTo[reac].end(),vFrom[reac][i]) == vTo[reac].end()){
166:         indiv = vFrom[reac][i];
167:         nbFrom =compartments[indiv];
168:         isEnough.push_back(nbFrom>=nbReac);
169:       }
170:     }
171:     return (is_true(all(as<LogicalVector>( wrap(isEnough)) == TRUE))) ;
172:   }
173:   
174: 
175:   void performReaction(int reac, int nbTime){
176:     string indiv="";
177:     for(unsigned i=0;i<vFrom[reac].size();i++){
178:       indiv = vFrom[reac][i];
179:       compartments[indiv]-=nbTime;
180:     }
181:     for(unsigned i=0;i<vTo[reac].size();i++){
182:       indiv = vTo[reac][i];
183:       compartments[indiv]+=nbTime;
184:     }
185:   }
186:   
187: 
188:   double rexp(const double& rate){
189:     double rand = 0.0;
190:     try{
191:       std::exponential_distribution<double> exponential(rate);
192:       rand = exponential(randomGenerator_);
193:     }
194:     catch (int e){
195:       Rcpp::stop("Error in Gillespie::rexp(rate)");
196:     }
197:     return rand;
198:   }
199:   
200: 
201:   unsigned rpois(const double& rate){
202:     unsigned rand = 0;
203:     try{
204:       std::poisson_distribution<unsigned> poisson(rate);
205:       rand = poisson(randomGenerator_);
206:     }
207:     catch (int e){
208:       Rcpp::stop("Error in Gillespie::rpois(rate)");
209:     }
210:     return rand;
211:   }
212:   
213: 
214:   List GillespieSimulation(){
215:   if(verbose_){
216:     Rcout << "Running simulation of the trajectory..." << endl;
217:   }
218:   bool ok = false;
219:   auto start_ = std::chrono::high_resolution_clock::now();
220:   auto stop_ = std::chrono::high_resolution_clock::now();
221:   if (deltaT_ > 0){
222:   if(isSwitchingMode_){
223:   unsigned i = 0;
224:   if (nTrials_ > 1){
225:     if(verbose_){
226:       Rcout << "- Trial " << (i+1) << "..." << endl;
227:     }
228:   }
229:   start_ = std::chrono::high_resolution_clock::now();
230:   updateDataFrameOutput();
231:   ok = runWithWitchingMode();
232:   stop_ = std::chrono::high_resolution_clock::now();
233:   for (i = 1; i < nTrials_ && !ok; i++){
234:   reInitializeDataFrame();
235:   if(verbose_){
236:     Rcout << "- Trial " << (i+1) << "..." << endl;
237:   }
238:   start_ = std::chrono::high_resolution_clock::now();
239:   ok = runWithWitchingMode();
240:   stop_ = std::chrono::high_resolution_clock::now();
241:   }
242:   }
243:   else{
244:   unsigned i = 0;
245:   if (nTrials_ > 1){
246:     if(verbose_){
247:       Rcout << "- Trial " << (i+1) << "..." << endl;
248:     }
249:   }
250:   start_ = std::chrono::high_resolution_clock::now();
251:   updateDataFrameOutput();
252:   ok = runTau();
253:   stop_ = std::chrono::high_resolution_clock::now();
254:   for (i = 1; i < nTrials_ && !ok; i++){
255:   reInitializeDataFrame();
256:   if(verbose_){
257:     Rcout << "- Trial " << (i+1) << "..." << endl;
258:   }
259:   start_ = std::chrono::high_resolution_clock::now();
260:   ok = runTau();
261:   stop_ = std::chrono::high_resolution_clock::now();
262:   }
263:   }
264:   }
265:   else{
266:   unsigned i = 0;
267:   if (nTrials_ > 1){
268:     if(verbose_){
269:       Rcout << "- Trial " << (i+1) << "..." << endl;
270:     }
271:   }
272:   start_ = std::chrono::high_resolution_clock::now();
273:   updateDataFrameOutput();
274:   ok = runDirect();
275:   stop_ = std::chrono::high_resolution_clock::now();
276:   for (i = 1; i < nTrials_ && !ok; i++){
277:   reInitializeDataFrame();
278:     if(verbose_){
279:       Rcout << "- Trial " << (i+1) << "..." << endl;
280:     }
281:   start_ = std::chrono::high_resolution_clock::now();
282:   ok = runDirect();
283:   stop_ = std::chrono::high_resolution_clock::now();
284:   }
285:   }
286:   if (ok){
287:   
288: 	int numCol=6;
289: 	Rcpp::List long_list(numCol);
290: 	Rcpp::CharacterVector namevec(numCol);
291: 	long_list[0]=dfTimes;
292: 	long_list[1]=dfreactions;
293: 	long_list[2]=dfNrep;
294: 	long_list[3]=dfS;
295: 	long_list[4]=dfI;
296: 	long_list[5]=dfR;
297: 	namevec[0]="Time";
298: 	namevec[1]="Reaction";
299: 	namevec[2]="Nrep";
300: 	namevec[3]="S";
301: 	namevec[4]="I";
302: 	namevec[5]="R";
303: 	long_list.attr("names") = namevec;
304: 	long_list.attr("row.names") = Rcpp::IntegerVector::create(NA_INTEGER, dfTimes.size());
305: 	long_list.attr("class") = "data.frame";
306: 	auto elapsed = stop_ - start_;
307: 	     if(verbose_){Rcout << "Operation took: " << std::chrono::duration_cast<std::chrono::microseconds>(elapsed).count() << " microseconds." << endl;}
308: 	return long_list;
309: 	}
310: else{
311: return NULL;
312: }
313: }
314: 
315:   bool runWithWitchingMode(){
316:   unsigned timePart = 0;
317:   time_ = vTimes_[timePart];
318:   int timePartLim = (vTimes_.size()-1);
319:   initParams(timePart);
320:   double jump = 1;
321:   double totalRate = 1;
322:   unsigned switchingThreshold = 0;
323:   int nEvents = 0;
324:   for ( ; timePart<timePartLim && computeTotalRate()!=0 && nEvents>=0 ; timePart++) {
325:   initParams(timePart);
326:   totalRate = computeTotalRate();
327:   jump = rexp(totalRate);
328:   while(continueCondition(timePart) && nEvents>=0 ){
329:   if(jump < deltaT_/10.0){
330:   switchingThreshold ++;
331:   }
332:   else{
333:   switchingThreshold = 0;
334:   }
335:   if(switchingThreshold > 10 || ((double)nEvents/(double)vreactions.size()) > 1){
336:   nEvents = tauLeapAlgo();
337:   jump = deltaT_;
338:   switchingThreshold = 0;
339:   }
340:   else{
341:   jump = directAlgo();
342:   nEvents =1;
343:   }
344:   }
345:   }
346:   return (time_>vTimes_[vTimes_.size()-1] || (abs(vTimes_[vTimes_.size()-1] - time_)<(deltaT_/10)));
347:   }
348:   
349: 
350:   bool runDirect(){
351:   unsigned timePart = 0;
352:   time_ = vTimes_[timePart];
353:   int timePartLim = (vTimes_.size()-1);
354:   initParams(timePart);
355:   for ( ; timePart<timePartLim && computeTotalRate()!=0 ; timePart++) {
356:   initParams(timePart);
357:   while(continueCondition(timePart)){
358:   double totalRate = 0.0;
359:   double jump = 0.0;
360:   int reactIndx = 0;
361:   totalRate = computeTotalRate();
362:   jump = rexp(totalRate);
363:   time_ += jump;
364:   reactIndx = whichReaction(totalRate);
365:   performReaction(reactIndx,1);
366:   updateCompartments();
367:   updateDataFrameOutput();
368:   updatereactionsOutput(reactIndx,1);
369:   updateRates();
370:   }
371:   }
372:   return (time_>vTimes_[vTimes_.size()-1] || (abs(vTimes_[vTimes_.size()-1] - time_)<(deltaT_/10)));
373:   }
374:   
375: 
376:   double directAlgo(){
377:   double totalRate = 0.0;
378:   double jump = 0.0;
379:   int reactIndx = 0;
380:   totalRate = computeTotalRate();
381:   jump = rexp(totalRate);
382:   time_ += jump;
383:   reactIndx = whichReaction(totalRate);
384:   performReaction(reactIndx,1);
385:   updateCompartments();
386:   updateDataFrameOutput(); 
387:   updatereactionsOutput(reactIndx,1);
388:   updateRates();
389:   return jump;
390:   }
391:   
392: 
393:   bool runTau(){
394:     unsigned timePart = 0;
395:     time_ = vTimes_[timePart];
396:     int timePartLim = (vTimes_.size()-1);
397:     initParams(timePart);
398:     int nEvents = 0;
399:     for ( ; timePart<timePartLim && computeTotalRate()!=0 && nEvents>=0 ; timePart++) {
400:       initParams(timePart);
401:       while(continueCondition(timePart) && nEvents>=0 ){
402:         nEvents = tauLeapAlgo();
403:       }
404:     }
405:     return (time_>vTimes_[vTimes_.size()-1] || (abs(vTimes_[vTimes_.size()-1] - time_)<(deltaT_/10)));
406:   }
407:   
408: 
409:   int tauLeapAlgo(){
410:   unsigned nEvents = 0;
411:     vector<pair<int,int> > reactionsToPerform;
412:     int indx = 0 ;
413:     vector<double>::iterator it;
414:     bool ok = TRUE;
415:     for (it = vRates_.begin(); it!=vRates_.end() && ok ; ++it,indx++) {
416:       unsigned nTime = 0 ;
417:       double rate = *it * deltaT_;
418:       if(rate > 0 && rate < 1000000000){
419:         nTime = rpois(rate) ;
420:         unsigned limit = 20;
421:         while(limit > 0 && !isFromSizeEnough(indx, nTime)){
422:           nTime = rpois(rate);
423:           limit--;
424:         }
425:         if(limit == 0 && !isFromSizeEnough(indx, nTime)){
426:           ok = FALSE;
427:           warning("Error : Stuck in Poisson distribution.You should try a smaller value for the time step tau.");
428:         }
429:       }
430:       if (rate > 1000000000){
431:         ok = FALSE;
432:         warning("Error: total rate too high. You should try other parameter or deltaT values.");
433:       }
434:       if (nTime >= numeric_limits<int>::max()){
435:         ok = FALSE;
436:         warning("Error: Number of events to perform has reached the maximal INT value");
437:       }
438:       if (nTime > 0){
439:         reactionsToPerform.push_back(make_pair(indx, nTime));
440:         nEvents += nTime;
441:       }
442:     }
443:     if(ok){
444:       time_ += deltaT_ ;
445:       for(unsigned i = 0; i<reactionsToPerform.size() ; i++){
446:         int reac = reactionsToPerform[i].first;
447:         int nbTime = reactionsToPerform[i].second;
448:         performReaction(reac, nbTime);
449:         updateCompartments();
450:         updateDataFrameOutput();
451:         updatereactionsOutput(reac,nbTime);
452:         updateRates();
453:       }
454:     }
455:     else{
456:       nEvents = -1;
457:     }
458:     return nEvents;
459:   }
460:   
461: bool continueCondition(unsigned timePart){
462: 	return ( computeTotalRate()!=0 && ((time_ < vTimes_[timePart+1]) && !(abs(vTimes_[timePart+1] - time_)<(deltaT_/10)))) ;
463: }
464: void updateDataFrameOutput(){
465: 	dfTimes.push_back(time_);
466: 	
467: 	dfS.push_back(S);
468: 	dfI.push_back(I);
469: 	dfR.push_back(R);
470: }
471: 
472:   void updatereactionsOutput(int indxReac, int nTime){
473:     dfreactions.push_back(vreactions[indxReac]);
474:     dfNrep.push_back(nTime);
475:   }
476:   
477: 
478: };
479: 
480: // declarations
481: extern "C" {
482: SEXP file18a7c14b3309( SEXP paramValues, SEXP times, SEXP initialStates, SEXP dT, SEXP nTrials, SEXP x) ;
483: }
484: 
485: // definition
486: SEXP file18a7c14b3309(SEXP paramValues, SEXP times, SEXP initialStates, SEXP dT, SEXP nTrials, SEXP x) {
487: BEGIN_RCPP
488: 
489:     // [[Rcpp::plugins(cpp11)]]
490:     List theta_(paramValues);
491:     NumericVector times_(times);
492:     NumericVector init_(initialStates);
493:     double dT_ = as<double>(dT);
494:     int nTrial_ = as<int>(nTrials);
495:     
496:     bool switching_ = LOGICAL(x)[0];
497:     bool verbose_ = LOGICAL(x)[1];
498:     
499:     reactions simu(theta_,init_,times_,dT_,nTrial_,switching_,verbose_);
500:     
501:     List traj = simu.GillespieSimulation();
502:     return traj;
503:     
504: END_RCPP
505: }

Compilation ERROR, function(s)/method(s) not created!
Error in compileCode(f, code, language = language, verbose = verbose) : 
  Warning message:In system(cmd) : 'make' not found
Calls: build_simulator -> cxxfunction -> compileCode
Execution halted