Servicing models with R using Plumber package

Shirin Glander made a great post about how to use Plumber to provide some servicing of R models an API. For whom are looking for methods to deploy ML learning algorithms in R in production, this post is mandatory.

The plumber package for R makes it easy to expose existing R code as a webservice via an API (https://www.rplumber.io/, Trestle Technology, LLC 2017).

You take an existing R script and make it accessible with plumber by simply adding a few lines of comments. If you have worked with Roxygen before, e.g. when building a package, you will already be familiar with the core concepts. If not, here are the most important things to know:

  • you define the output or endpoint
  • you can add additional annotation to customize your input, output and other functionalities of your API
  • you can define every input parameter that will go into your function
  • every such annotation will begin with either #' or #*

< p class=”js-evernote-checked” style=”padding-left:60px;”>With this setup, we can take a trained machine learning model and make it available as an API. With this API, other programs can access it and use it to make predictions.