<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/simmer-4-0-0/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://www.enchufa2.es/archives/simmer-4-0-0.html"> R – Enchufa2</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>The 4.0.0 release of <a rel="nofollow" href="http://r-simmer.org/" target="_blank">simmer</a>, the Discrete-Event Simulator for R, is on CRAN under a new license: we decided to switch to GPL >= 2. Most notably in this major release, the C++ core has been refactorised and exposed under <code>inst/include</code>. This is not a big deal for most users, but it enables extensions. As an example of this, <a rel="nofollow" href="https://github.com/r-simmer/simmer.mon" target="_blank"><code>simmer.mon</code></a> is an experimental package that links to <code>simmer</code> and extends its monitoring facilities to provide a new DBI-based backend. Not a very efficient one, but it demonstrates how to extend the <code>simmer</code> core from another package.</p>
<p>Exception handling has been remarkably improved. In previous releases, errors were reported to happen in the <code>run()</code> method, which is… everything that can happen, obviously. In this version, errors are catched and more information is provided, particularly about the simulation time, the arrival and the activity involved:</p>
<pre><code><span>library</span>(simmer)

bad.traj &lt;- trajectory() %>%
  timeout(<span>function</span>() <span>NA</span>)

simmer() %>%
  add_generator(<span>&quot;dummy&quot;</span>, bad.traj, at(pi)) %>%
  run()</code></pre>
<pre><code>## Error: 'dummy0' at 3.14 in 'Timeout':
##  missing value (NA or NaN returned)</code></pre>
<p>Another improvement has to do with attributes. These are commonly used to build incremental indices, but some boilerplate was needed to initialise them. Now this is automatic (and configurable):</p>
<pre><code>index.traj &lt;- trajectory() %>%
  set_global(<span>&quot;index&quot;</span>, <span>1</span>, mod=<span>&quot;+&quot;</span>, init=<span>10</span>)

simmer() %>%
  add_generator(<span>&quot;dummy&quot;</span>, index.traj, at(<span>1</span>:<span>3</span>), mon=<span>2</span>) %>%
  run() %>%
  get_mon_attributes()</code></pre>
<pre><code>##   time name   key value replication
## 1    1      index    11           1
## 2    2      index    12           1
## 3    3      index    13           1</code></pre>
<p>Finally, the <code>log_</code> activity was created for occasional debugging, but we noticed that <code>simmer</code> users use it a lot more to know what is happening when they build models, but so much output is annoying when a model is complete. Therefore, we have implemented simulation-scoped logging levels to be able to turn on and off specific messages on demand:</p>
<pre><code>log.traj &lt;- trajectory() %>%
  log_(<span>&quot;This will be always printed&quot;</span>) %>% <span># level=0</span>
  log_(<span>&quot;This can be disabled&quot;</span>, level=<span>1</span>)

simmer(log_level=<span>1</span>) %>%
  add_generator(<span>&quot;dummy&quot;</span>, log.traj, at(pi)) %>%
  run() %>% invisible()</code></pre>
<pre><code>## 3.14159: dummy0: This will be always printed
## 3.14159: dummy0: This can be disabled</code></pre>
<pre><code>simmer() %>% <span># log_level=0</span>
  add_generator(<span>&quot;dummy&quot;</span>, log.traj, at(pi)) %>%
  run() %>% invisible()</code></pre>
<pre><code>## 3.14159: dummy0: This will be always printed</code></pre>
<p>See below for a comprehensive list of changes.</p>
<div>
<h3>New features:</h3>
<ul>
<li>The C++ core has been refactorised into a header-only library under <code>inst/include</code> (#147 closing #145). Therefore, from now on it is possible to extend the C++ API from another package by listing <code>simmer</code> under the <code>LinkingTo</code> field in the DESCRIPTION file.</li>
<li>New generic <code>monitor</code> constructor enables the development of new monitoring backends in other packages (179f656, as part of #147).</li>
<li>New simulation-scoped logging levels. The <code>log_</code> activity has a new argument <code>level</code> which determines whether the message is printed depending on a global <code>log_level</code> defined in the <code>simmer</code> constructor (#152).</li>
<li><code>set_attribute</code> and <code>set_global</code> gain a new argument to automatically initialise new attributes (#157). Useful to update counters and indexes in a single line, without initialisation boilerplate.</li>
</ul>
</div>
<div>
<h3>Minor changes and fixes:</h3>
<ul>
<li>Enhanced exception handling, with more informative error messages (#148).</li>
<li>Refactorisation of the printing methods and associated code (#149).</li>
<li>Allow empty trajectories in sources and activities with sub-trajectories (#151 closing #150).</li>
<li>Enable <code>-DRCPP_PROTECTED_EVAL</code> (Rcpp >= 0.12.17.3), which provides fast evaluation of R expressions by leveraging the new stack unwinding protection API (R >= 3.5.0).</li>
<li>Replace backspace usage in vector’s <code>ostream</code> method (2b2f43e).</li>
<li>Fix namespace clashes with <code>rlang</code> and <code>purrr</code> (#154).</li>
</ul>
</div>
<p><em>Article originally published in Enchufa2.es: <a rel="nofollow" href="https://www.enchufa2.es/archives/simmer-4-0-0.html" target="_blank">simmer 4.0.0</a></em>.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://www.enchufa2.es/archives/simmer-4-0-0.html"> R – Enchufa2</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/ER92anGN-rg" height="1"></a></div>