Mortar has joined Datadog, the leading SaaS-based monitoring service for cloud applications. Read more about what this means here.

R Tasks

R Tasks run R scripts for sophisticated statistical computing and graphing.


These Tasks are part of the mortar-luigi project, an open-source collection of extensions for using Mortar from within Luigi. It is installed automatically when you use the mortar local:luigi or mortar luigi commands.


Runs an R script on Mortar.

Example Usage

class MyExampleRTask(mortartask.MortarRTask):

    # Example parameters for R script
    input_path = luigi.Parameter()
    output_path = luigi.Parameter()

    def requires(self):
        return [OtherTask()]

    def arguments(self):
        Command-line arguments pass to the R script,
        in this case input and output paths
        return [self.input_path(),

    def rscript(self):
        Path to the R script to run, relative to the root of your Mortar project.
       return "rscripts/my_r_script.R"

There are two R-specific elements here:

  • arguments passes arguments to the R script, just as you would pass parameters when running an R script from the command line.
  • rscript tells Luigi where to find the R script (relative to the root of your Mortar project) that runs in this Task.

Note that two of the methods required for any Luigi Task, output and run, are covered by the general MortarRTask class, so you do not have to include them when writing your own R script Tasks.

requires is a method that needs to be defined for every Luigi task, and it indicates dependencies for the task. This can either be other Luigi tasks, data in a specified location, or nothing.

Example in Context

Mortar's example R pipeline uses a MortarRTask to run an R script that plots data from the Olympics using ggplot2.