• ## simmer v3.5.0 released on CRAN

We are proud to present simmer 3.5.0, a new release on CRAN of the Discrete-Event Simulator for R with a bunch of exciting features:

• Simpler logging. So far, if we wanted arrivals to print something into the console, we had, for instance, to make a custom function returning zero, with a print() inside, and to put it into a timeout() activity. Now, with log_() it’s easier and, in addition, you get the simulation time and the arrival name:
library(simmer)

sayer <- create_trajectory() %>%
log_("hello world!")

simmer() %>%
run() %>% invisible

## 3: dummy0: hello world!
## 6: dummy1: hello world!

• New resource modifiers. set_capacity() and set_queue_size() existed before, but they were not very useful. Now, these methods become activities and you can use them in your trajectories. They have their associated set_capacity_selected() and set_queue_size_selected(), just like seize() and release(), for a joint use with the resource selector select().
• New generator modifiers. Activities activate(), deactivate() allow us to start/stop generators from within trajectories. Activities set_trajectory(), set_distribution() allow us to change a generator’s assigned trajectory or distribution respectively.
• New interarrival communication activities, allowing asynchronous programming. send(), trap(), untrap() and wait() can be used to send signals, wait for signals, trap them and launch asynchronous handlers. Nothing better than an example to understand the possibilities of this mechanism:
library(simmer)

t_blocked <- create_trajectory() %>%
trap("you shall pass",
handler = create_trajectory() %>%
log_("ok, I'm packing...") %>%
timeout(1)) %>%
log_("waiting...") %>%
wait() %>%
log_("and I'm leaving!")

t_signaler <- create_trajectory() %>%
log_("you shall pass") %>%
send("you shall pass")

simmer() %>%
run() %>% invisible

## 0: blocked0: waiting...
## 5: signaler0: you shall pass
## 5: blocked0: ok, I'm packing...
## 6: blocked0: and I'm leaving!


Other interesting new features from past releases since our last post include post-seize and reject optional trajectories when seizing resources, arrival cloning and synchronizing, arrival batching and separating or reneging.

Please, refer to the updated Advanced Trajectory Usage vignette for more information and examples. Also remember that you can participate in our simmer-devel mailing list to get help, discuss methodologies… any feedback is always welcome.

• ## Introducing artyfarty: a theming package for ggplot2

In the last few years, I’ve been using ggplot2 quite a lot. While the
ggplot2 default theme is quite slick, I started tweaking the theme to
fit my own taste and/or that of the target audience.

artyfarty is a collection of a few themes that I have used through the
years. While still a work in progress, and thus no CRAN release planned
for the moment, you can already try it out and see a collection of
themes: https://github.com/Bart6114/artyfarty.

library(ggplot2)
library(artyfarty)

ggplot(iris) +
aes(x=Sepal.Length, y=Sepal.Width, color=Species) +
geom_point() +
scale_colour_manual(values = pal("flatpaleta")) +
theme_flat() +
ggtitle("Iris - sepal")


Or with a watermark:

ggplot(iris) +
aes(x=Sepal.Length, y=Sepal.Width, color=Species) +
watermark_img("flower.png") +
geom_point() +
scale_colour_manual(values = pal("flatpaleta")) +
theme_flat() +
ggtitle("Iris - sepal")


• ## Simulating Continuous-Time Markov Chains with simmer (part 2)

In part one, we simulated a simple CTMC. Now, let us complicate things a bit. Remember the example problem there:

A gas station has a single pump and no space for vehicles to wait (if a vehicle arrives and the pump is not available, it leaves). Vehicles arrive to the gas station following a Poisson process with a rate of $\lambda=3/20$ vehicles per minute, of which 75% are cars and 25% are motorcycles. The refuelling time can be modelled with an exponential random variable with mean 8 minutes for cars and 3 minutes for motorcycles, that is, the services rates are $\mu_\mathrm{c}=1/8$ cars and $\mu_\mathrm{m}=1/3$ motorcycles per minute respectively (note that, in this context, $\mu$ is a rate, not a mean).

Consider the previous example, but, this time, there is space for one motorcycle to wait while the pump is being used by another vehicle. In other words, cars see a queue size of 0 and motorcycles see a queue size of 1.

The new Markov chain is the following:

where the states car+ and m/c+ represent car + waiting motorcycle and motorcycle + waiting motorcycle respectively.

With $p$ the steady state distribution, the average number of vehicles in the system is given by

• ## Simulating Continuous-Time Markov Chains with simmer (part 1)

In the previous post, we gave you some insights about the simulation of simple birth-death processes with simmer. The extension of such a methodology for more complex queueing networks is immediate and was left as an exercise for the reader.

Similarly, today we are going to explore more features of simmer with a simple Continuous-Time Markov Chain (CTMC) problem as an excuse. CTMCs are more general than birth-death processes (those are special cases of CTMCs) and may push the limits of our simulator. So let’s start.

• ## Simulating queueing systems with simmer

We are very pleased to announce that a new release of simmer, the Discrete-Event Simulator for R, is on CRAN. There are quite a few changes and fixes, with the support of preemption as a star new feature. Check out the complete set of release notes here.

Let’s simmer for a bit and see how this package can be used to simulate queueing systems in a very straightforward way.

• ## simmer v3.1.1 released on CRAN

Last week the latest version of simmer was released on CRAN: v3.1.1.

This version allows adding attributes to arrivals (and basing decisions on their values).

Also, the rollback activity was introduced, enabling you to roll back a trajectory with n steps.

In addition, a new priority param for the seize() command was introduced. This allows ordering a resource queue based on the arrival’s seize priority.

Check the vignettes on simmer’s CRAN page to get started.

### Overview

New features:

• Add attributes to arrivals and new set_attribute activity (#16).
• New rollback activity (#17 and #22).
• Add priorities to resources’ queue (#20).

Minor changes and fixes:

• Performance improvements with Boost (1b654fd).
• Fix arrivals’ timing issues (#24).
• Nicer object printing (#26).
• Return self visibly, instead of invisibly (#35).
• Add at and from convenience functions (29cccd2 and 7cfdd90).
• Some work on vignettes (#29).
• Fix ggplot2 2.0.0 compatibility issues (#37).
• ## Making an R based ML model accessible through a simple API

Building an accurate machine learning (ML) model is a feat on its own. But once you’re there, you still need to find a way to make the model accessible to users. If you want to create a GUI for it, the obvious approach is going after shiny. However, often you don’t want a direct GUI for a ML model but you want to integrate the logic you’ve created into an existing (or new) application things become a bit more difficult.

Let’s say you’ve created a robust ML model in R and explain the model to your in-house IT department, it is (currently) definitely not a given that they can easily integrate it. Be it either due to the technology used is unfamiliar to them or because they simply don’t have a in-depth knowledge on ML.

• ## simmer 3.0.0 is on CRAN

I’m very pleased to announce the first CRAN release of simmer. (https://cran.rstudio.com/web/packages/simmer/). This release has been realised thanks to the efforts made by Iñaki.

To reiterate a bit, simmer is a discrete-event simulation (DES) package for R. It is the first R package that focuses on creating a robust DES framework for R. It provides a framework somewhat similar as e.g SimPy and SimJulia but is arguably written from a bit more of an applied angle.

R might not be the most efficient language to implement a DES framework due to its method of memory allocation. Therefore, simmer implements a C++ backend by making use of Rcpp.

• ## jug 0.1.0 on CRAN

Jug is a package to allow you to easily create web APIs based on your R codestack.

Documentation and examples can be found at: http://bart6114.github.io/jug/

• ## Jug: Easily Create R APIs

Jug stands for Just Unified Galloping. Okay, okay, it’s just a play on words coming from a Flask (Python) background.

Jug is my attempt to create a simple small web framework that allows you to turn your (existing) R functions into an API. Having the wonderful httpuv package at my disposal made this very easy for me.

So, how does this work?

Let’s say I have the following function:

say_hello_to<-function(name) paste("Hello", name)


Sometimes you would be in a situation where you want to send a GET request to a server and let a function (let’s say the one above) return it’s result. Thus, I want to expose the above function to allow HTTP GET requests to acces it. Using Jug I could do something like this:

library(jug)

jug() %>%
gett("/", decorate(say_hello_to)) %>%
serve_it()

Serving the jug at http://127.0.0.1:8080


However, when I run this code and post a GET request to the URL, the following happens:

$curl 127.0.0.1:8080 ERROR: argument "name" is missing, with no default  Obviously, because the function say_hello_to requires the parameter name. A second attempt has better results: $ curl 127.0.0.1:8080/?name=Bart
Hello Bart


• ## dimple charts for R

Making use of the nice htmlwidgets package it only took a minimum amount of coding to make the dimple library available from R.

You can find the dimple R package at github.com/Bart6114/dimple and some documentation and examples at: bart6114.github.io/dimple (can take a while to load). Using the package you can create static javascript-based graphs, but you can also use dimple charts in Shiny applications.

• ## licorice: plot Likert-like data

I wanted to create a nice visualization from a survey data set. I quickly stumbled upon the likert package (go check it out).

I did however have some trouble getting it to work the way I wanted. Therefore I made a quick implementation of my own that you can install from GitHub: github.com/Bart6114/licorice (check out the GitHub README for more info).

Below you can see an example plot. It is a basic ggplot2 object which you can add upon to your liking. The plot below has been themed using the ggthemr package.

• ## infuser: a template engine for R

Version 0.1 of infuser was just released on CRAN.

infuser is a very basic templating engine. It allows you to replace parameters in character strings or text files with a given specified value.

I would often include some SQL code in my R scripts so that I could make parameters in the SQL code variable. But I was always a bit hesitant on the cleanliness of this. It irked me so much that I finally wrote this very simple package. The infuse function allows me to read in a text file (or a character string for that matter) and infuse it with the requested values.

• ## sparklines for R

I’ve always liked the jQuery Sparklines library and today I had a use case for implementing these in one of my Rmarkdown reports.

While it wouldn’t be too difficult to staticly include a javascript based chart, ideally I would simply want to dynamically generate the sparkline using values computed in R. Luckily we now have htmlwidgets for R. This library makes it stupidly simple to integrate javascript libraries in R code. It simply up to one who has a use case for integrating a javascript library with R to insert some glue code: and so sparklines was born.

• ## scheduleR receives big update

For the newcomers; scheduleR is a framework to deploy/schedule R tasks, reports and Shiny apps. The tool has an integrated logging and notification system to ease the maintenance of scheduled R related jobs.

After a lot of refactoring the tasks have been separated into tasks (e.g. ETL scripts) and reports (rmarkdown). The back-end that handles the execution of R scripts has gotten a polish, as did the UI.

• ## Compensation in artifical neural networks

Last week I was at the succesful doctoral defence of Wouter on the role of the cerebellum while walking. During the questions, the topic of compensation came up: if a part of your neural system gets damaged can other parts (over time) take over some of its functionality? The answer is most probably yes, but only to some extent.

• ## New blog

%\$*! my server crashed… Oh well, might as well take this opportunity to start with a fresh blog platform. I’ll be using Jekyll from now on.

The texts of my posts have (mostly) been preserved, I will start recovering old posts in the coming days / weeks.

• ## scheduleR: a web interface to schedule .R & .Rmd scripts

This post has been transferred from another blog platform and could have dead links / incorrect lay-out.

scheduleR is an attempt to create an intuitive interface for scheduling R and Rmarkdown scripts. Especially for the latter, I find the lack of a good scheduling, logging and notification tool the reason for why I don’t use Rmarkdown as much as I could for generating business report / dashboards.