R Functions
To calculate data with the help of R, you need to define an R script to be executed by Insight during data load or an on-demand basis. R functions are Insight documents that contain R scripts and describe how to invoke R to calculate any field value.
You can create an R function either based on an R model or without it.
- In Studio, on the Documents Tree, right-click R Functions and select New R Function.
- Assign a unique, descriptive name to the new function and click OK.
-
On the
Model tab, define the
following:
- Model (optional): Select from the list of previously created models.
- Model parameter (optional): Specify the name for the R model variable to be used in the R script.
- Input data variable name: Specify the variable name to be used in the R script.
- Output data variable name: Specify the variable name to be used in the R script.
- Output data variable type: Select the output type from the list.
-
On the
Arguments tab, define the
list of arguments to be used in the R script. Also, you may add additional
function arguments, because for clusterization you need to specify cluster
count or maximum radius between clusters.
-
Add variables that depend on record lines to the Function data arguments table. For example, a city can be a variable since it changes from line to line. All lines from this table are variable parameters of this function.
-
Add constant parameters for the record to the Additional function arguments table. Such parameters are the same for all record lines. For example, the revenue is always measured in US dollars for the record.
-
-
On the
Script tab, define the
string for the R script to be executed during calculation. The script can use
the input data frame and function arguments by name. In the following script,
the
IntConstant argument is added (+) to
IntValue argument.
OutputData <- InputData$IntValue + IntConstant
- Save the R function.