Example

This example demonstrates how to use the RScript Agent to take three values as input and output the sum of the three input values as well as the difference.

Refer to configuration to understand all configuration options of this Agent.

Step 1: Add the Agent

Drag the RScript Agent onto the canvas, link the input endpoint to the numeric data, and the output to the printer. Rename the Agent and save the Data Stream.

Step 2: Configure General

Select the Agent and click Configure. Keep the default Collection.

Step 3: Configure Script

Enter your script. In this case, copy the script below and paste it into the text editor.

addition = function(a,b,c){
    print(a+b+c)
}
substraction = function(a,b,c){
    print(a-b-c)
}
 x = Value1
 y = Value2
 z = Value3
dataAdd <- addition(x,y,z)
dataMinus <- substraction(x,y,z)

Step 4: Configure Output

Choose the payload option and enter the name and data type of the output variable(s).

In this case, add the output variables dataAdd and dataMinus, both with a type of Int.

Step 5: Results

Apply the changes, save the Data Stream, and publish it.

Let's look at the Live Data View. Observe that DataAdd and DataMinus are appended to the incoming events. They contain the script's variables, which are the sum and difference respectively of Value1, Value2, and Value3.

Files

See the Import, Export, and Clone - XMPro article for steps to import a Data Stream.

Last updated