• Discontinuing maintenance of jug

    I’m starting off 2018 with dropping my involvement with jug. The reason for this being that I simply cannot find the time or interest anymore to maintain the code.

    All of the open-source efforts that I started always had to do with a concrete need that I had in one way or another. Once that need is fulfilled by creating a solution for it, the next challenge becomes to maintain that solution.

    In a best case scenario, someone with the right set of skills will continue the development into a mature project which become significant better then the original solution. A close to my heart example of this is simmer (see http://r-simmer.org/), where Iñaki Ucar has taken over the development and has improved the original enormously.

    However, for jug the active developers community is currently too small too do a handover. Next to that, jug its main competitor plumber (see website) has been able to create a significant community with highly active support.

    Today I have to sort of admit defeat. My own time availability as co-founder of dataroots and my changing interests unfortunately no long allow me to put in the time and effort required to do the unnecessary maintenance to do justice to the jug user base. therefore I will be discontinuing the maintenance of jug. If anyone would be willing to take over, they will be more than welcome.

  • Extensions for simmer

    A new version of the Discrete-Event Simulator for R was released a few days ago on CRAN. The most interesting new feature is the implementation of the subsetting operators [ and [[ for trajectory objects. Basically, think about trajectories as lists of activities and these operators will do (almost) everything you expect.

    t0 <- trajectory() %>%
      seize("resource", 1) %>%
      timeout(function() rexp(1, 2)) %>%
      release("resource", 2)
    ## trajectory: anonymous, 3 activities
    ## { Activity: Seize        | resource: resource | amount: 1 }
    ## { Activity: Timeout      | delay: 0x7fdfa229cfb8 }
    ## { Activity: Release      | resource: resource | amount: 2 }
    t0[c(3, 1)]
    ## trajectory: anonymous, 2 activities
    ## { Activity: Release      | resource: resource | amount: 2 }
    ## { Activity: Seize        | resource: resource | amount: 1 }

    After the last maintenance update (v3.5.1), which fixed several bugs and included a new interesting vignette with SimPy examples translated to ‘simmer’, this v3.6.0 comes hand in hand with the first ‘simmer’ extension released on CRAN: simmer.plot.

    The primary purpose of ‘simmer.plot’ is to detach plotting capabilities from the core package, to systematise and enhance them. If you were using any of the old plot_*() functions, you will get a deprecation warning pointing to the S3 method simmer.plot::plot.simmer. This vignette will help you make the transition.

    ‘simmer.plot’ also implements a new plot S3 method for trajectories. It produces a diagram of a given trajectory object, which is very helpful for debugging and checking that everything conforms your simulation model. Let us consider, for instance, the following pretty complex trajectory:

    t0 <- trajectory() %>%
      seize("res0", 1) %>%
      branch(function() 1, c(TRUE, FALSE),
             trajectory() %>%
                     trajectory() %>%
                       seize("res1", 1) %>%
                       timeout(1) %>%
                       release("res1", 1),
                     trajectory() %>%
                            handler=trajectory() %>%
                              timeout(1)) %>%
             trajectory() %>%
               set_attribute("dummy", 1) %>%
               seize("res2", function() 1) %>%
               timeout(function() rnorm(1, 20)) %>%
               release("res2", function() 1) %>%
               release("res0", 1) %>%
               rollback(11)) %>%
      synchronize() %>%
      rollback(2) %>%
      release("res0", 1)

    We must ensure that:

    • Resources are seized and released as we expect.
    • Branches end (or continue) where we expect.
    • Rollbacks point back to the activity we expect.

    Things are indeed much easier if you can just inspect it visually:



    Note that different resources are mapped to a qualitative color scale, so that you can quickly glance whether you placed the appropriate seizes/releases for each resource.

    Other interesting ‘simmer’ extensions are already on our roadmap. Particularly, Bart has been simmering a new package (still under development) called simmer.optim, which brings parameter optimisation to ‘simmer’. While ‘simmer’, as is, can help you answer a question like the following:

    If we have x amount of resources of type A, what will the average waiting time in the process be?

    ‘simmer.optim’ is targeted to a reformulation like this:

    What amount x of resources of type A minimises the waiting time, while still maintaining a utilisation level of $\rho_A$?

    We would be very grateful if someone with experience on DES optimisation could try it out and give us some feedback. Simply install it from GitHub using ‘devtools’


    and start from the README, which demonstrates the current functionalities.

  • 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:
    sayer <- create_trajectory() %>%
      log_("hello world!")
    simmer() %>%
      add_generator("dummy", sayer, at(3, 6)) %>%
      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:
    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() %>%
      add_generator("blocked", t_blocked, at(0)) %>%
      add_generator("signaler", t_signaler, at(5)) %>%
      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.

    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

    Continue reading →

  • 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.

    Continue reading →

  • 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.

    Continue reading →

  • 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.


    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.

    Continue reading →

  • 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.

    Continue reading →

  • 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/

    Continue reading →

  • 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:

    jug() %>%
      gett("/", decorate(say_hello_to)) %>%
    Serving the jug at

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

    $ curl
    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
    Hello Bart

    Continue reading →

  • dimple charts for R

    dimple is a simple-to-use charting API powered by D3.js.

    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.

    Continue reading →

  • 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.

    Continue reading →

  • 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.

    Continue reading →

  • 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.

    Continue reading →

  • 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.

    Continue reading →

  • Introducing simmer: Discrete Event Simulation for R

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

    Please note: the syntax described here is no longer up-to-date, please refer to the readme at simmer’s GitHub page.

    The simmer package grew out of a personal need for a simple rapid development discrete event simulation (DES) framework. I work in the hospital sector and at times use a DES approach to simulate hospital processes / patient trajectories. DES can give you a quick look at process bottlenecks and test out the impact of alternative process set-ups.

    Continue reading →