UiPath Documentation
process-mining
2021.10
true

Process Mining user guide

Last updated May 5, 2026

Example: Creating an R Script

Introduction

This example explains how to interface the UiPath Process Mining platform with external R scripts to implement external data processing.

Installing R

Follow these steps to be able to use R-script in the platform.

Step

Action

1

Download the latest version of the R package from

https://cran.r-project.org/bin/windows/base/.

2

Install R on the server.

Note: this must be the server on which UiPath Process Mining is installed.

3

Locate the installation directory and find path of Rscript.exe.

For example: C:/Apps/Rscript.exe

R is installed on the server, and developers can connect to it with a connection string.

The installation path is needed to create connection strings for an R script.

Important:

Start with some dummy data, to test your workspace setup. For example, use the “Hello World” example as described in Example: Creating a Python Script. The dummy R script will than contain: write("Hello world!", stderr()); quit("default", 1)

High-level Overview

In this example an R script is created which clusters cases based on their traces.

Steps

  1. Setting up the Server Settings;
  2. Writing the script.
  3. Setting up the data source;
  4. Setting up a script data source;

Setting up the Server Settings

The generic script datasource requires handlers for all external processes that you want to run.

Follow these steps to add the script handler for R script.

StepAction
1Go to the Superadmin Settings tab.
2Add a field GenericScriptHandlers with as value an object with one key, “r”, which has as value the path to your python executable. For example: "GenericScriptHandlers": {"r": "C:/Apps/Rscript.exe",}
3Click on SAVE.

Writing the Script

In your text editor, start a blank text file and enter the following code.

# get command line arguments
args <- commandArgs(trailingOnly=TRUE)
inputfile <- args[1]
# read csv file
input <- file(inputfile, 'r')
df <- read.table(input, header=TRUE, sep=";")
# pre-processing
df <- table(df)
df <- as.data.frame.matrix(df)
df <- df[, sapply(data.frame(df), function(df) c(length(unique(df)))) > 1] #remove columns with unique value 
# cluster
df <- scale(df)
kc <- kmeans(df, centers = 5)
cluster <- kc$cluster
# output
resultdata <- cbind(rownames(df), cluster)
colnames(resultdata)[1] <- 'Case ID'
write.table(resultdata, row.names = FALSE, sep=";", qmethod = "double")
# get command line arguments
args <- commandArgs(trailingOnly=TRUE)
inputfile <- args[1]
# read csv file
input <- file(inputfile, 'r')
df <- read.table(input, header=TRUE, sep=";")
# pre-processing
df <- table(df)
df <- as.data.frame.matrix(df)
df <- df[, sapply(data.frame(df), function(df) c(length(unique(df)))) > 1] #remove columns with unique value 
# cluster
df <- scale(df)
kc <- kmeans(df, centers = 5)
cluster <- kc$cluster
# output
resultdata <- cbind(rownames(df), cluster)
colnames(resultdata)[1] <- 'Case ID'
write.table(resultdata, row.names = FALSE, sep=";", qmethod = "double")

Follow the steps below.

StepAction
1Save the text file as script.r.
2Upload the script.r file to your workspace.

Setting up the Data Source

To define input data, create an attribute that generates a .CSV like string. It should be placed in the Globals table since it will serve as input in a table definition.

Note:

You can use the csvtable function to define input data.

For this example, we have an application with the an Events table. See illustration below.

docs image

Follow these steps to create a lookup expression R_input_data from the Globals table to Events.

StepAction
1Open the app in your development environment, and go to the Data tab.
2Select the Globals table. Right-click on the Globals table in the table item list and select New expression….
3Set the type to Lookup.
4Select Events as input table.
5Enter the following expression: csvtable( 'CaseID', records.text(Case_ID) , 'Activity', records.text(Activity) )
6Enter R_input_data in the name field.
7Click on OK to save the expression attribute in the Globals table.

The expression attribute is created in the Globals table. See illustration below.

docs image

Setting up a Script Data Source

Next, set up a datasource table in the application which will call the script.

Follow these steps to set up the script data source.

StepAction
1In the Data tab, create a new Connection string table.
2Rename the New_table to RscriptExample.
3Right click on the RscriptExample table and click Advanced > Options….
4In the Table Options dialog, set the Table scope to Workspace.
5Double click on the RscriptExample table to open the Edit Connection String Table window.
6Enter the following as Connection string: ``'driver={mvscript
7Enter the following as Query: '' +'&scriptFile=' + urlencode("script.r") +'&inputData=' + urlencode(R_input_data) See illustration below.
8Click on OK, and click on YES to reload the data.

docs image

When loading the data, new attributes are detected. Click on YES(2x) and click on OK.

docs image

The Rscript_example table now has two datasource attributes, Case_ID and cluster.

See illustration below.

docs image

Defining the R Script in the Query Field

Instead of using a separate file containing the R script, you can also define the R script in the Query field of the Edit Connection String dialog. In this case you use the scriptText parameter in stead of the scriptFile parameter.

See illustration below.

docs image

Was this page helpful?

Connect

Need help? Support

Want to learn? UiPath Academy

Have questions? UiPath Forum

Stay updated