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.

  1. In Studio, on the Documents Tree, right-click R Functions and select New R Function.
  2. Assign a unique, descriptive name to the new function and click OK.
  3. On the Model tab, define the following:
    1. Model (optional): Select from the list of previously created models.
    2. Model parameter (optional): Specify the name for the R model variable to be used in the R script.
    3. Input data variable name: Specify the variable name to be used in the R script.
    4. Output data variable name: Specify the variable name to be used in the R script.
    5. Output data variable type: Select the output type from the list.
  4. 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.

  5. 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
  6. Save the R function.
Now the R function can be used in a derived field for records to calculate field values. You can also see how to create a sample derived field with the R function.