This article is originally published at https://www.enchufa2.es
The 4.0.0 release of simmer, 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
inst/include. This is not a big deal for most users, but it enables extensions. As an example of this,
simmer.mon is an experimental package that links to
simmer and extends its monitoring facilities to provide a new DBI-based backend. Not a very efficient one, but it demonstrates how to extend the
simmer core from another package.
Exception handling has been remarkably improved. In previous releases, errors were reported to happen in the
run() 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:
library(simmer) bad.traj <- trajectory() %>% timeout(function() NA) simmer() %>% add_generator("dummy", bad.traj, at(pi)) %>% run()
## Error: 'dummy0' at 3.14 in 'Timeout': ## missing value (NA or NaN returned)
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):
index.traj <- trajectory() %>% set_global("index", 1, mod="+", init=10) simmer() %>% add_generator("dummy", index.traj, at(1:3), mon=2) %>% run() %>% get_mon_attributes()
## time name key value replication ## 1 1 index 11 1 ## 2 2 index 12 1 ## 3 3 index 13 1
log_ activity was created for occasional debugging, but we noticed that
simmer 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:
log.traj <- trajectory() %>% log_("This will be always printed") %>% # level=0 log_("This can be disabled", level=1) simmer(log_level=1) %>% add_generator("dummy", log.traj, at(pi)) %>% run() %>% invisible()
## 3.14159: dummy0: This will be always printed ## 3.14159: dummy0: This can be disabled
simmer() %>% # log_level=0 add_generator("dummy", log.traj, at(pi)) %>% run() %>% invisible()
## 3.14159: dummy0: This will be always printed
See below for a comprehensive list of changes.
- The C++ core has been refactorised into a header-only library under
inst/include(#147 closing #145). Therefore, from now on it is possible to extend the C++ API from another package by listing
LinkingTofield in the DESCRIPTION file.
- New generic
monitorconstructor enables the development of new monitoring backends in other packages (179f656, as part of #147).
- New simulation-scoped logging levels. The
log_activity has a new argument
levelwhich determines whether the message is printed depending on a global
log_leveldefined in the
set_globalgain a new argument to automatically initialise new attributes (#157). Useful to update counters and indexes in a single line, without initialisation boilerplate.
Minor changes and fixes:
- Enhanced exception handling, with more informative error messages (#148).
- Refactorisation of the printing methods and associated code (#149).
- Allow empty trajectories in sources and activities with sub-trajectories (#151 closing #150).
-DRCPP_PROTECTED_EVAL(Rcpp >= 0.12.17.3), which provides fast evaluation of R expressions by leveraging the new stack unwinding protection API (R >= 3.5.0).
- Replace backspace usage in vector’s
- Fix namespace clashes with
Please visit source website for post related comments.