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.
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(), self.output_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:
argumentspasses arguments to the R script, just as you would pass parameters when running an R script from the command line.
rscripttells 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,
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.