Using R in a task type

R can be used in a task type if Core.Host.RScript is installed.

For example Example.RScript.PlotXY uses R to create a simple plot:

The main contains the boilerplate XamFlow input and output handling, and uses to execute an R script:

import xfworkerutil
import runutil

worker = xfworkerutil.XFWorkerJob()

inputs = worker.job['inputs']

# Download input files
table_path = worker.download_input_file(inputs['table'])

plot_path = worker.create_related_path(table_path, '_plot.png')

# Run R script
runutil.run_rscript(["Reg_1x_1y.R", str(table_path), str(plot_path)])

# Upload output files

# Save outputs
outputs = {
    "plot": worker.create_output_bitmap(,

The Reg_1x_1y.R script contains the R commands:


args = commandArgs(trailingOnly=TRUE)

# Open CSV-file
df = read.csv(args[1], header=TRUE)

# Column nr x-axis
x = colnames(df)[1]
# Column nr y-axis
y = colnames(df)[2]

# Regression line
myplot = ggplot(df) +
    geom_jitter(aes_string(x, y), shape=1, colour="blue") +
    geom_smooth(aes_string(x, y), method=lm, se=TRUE, color="blue")

# Save plot
ggsave(myplot, file=args[2])