How to Create an Expression Function


Use the Expression Functions dialog to register a function in the Spotfire expression language that is based on TIBCO Enterprise Runtime for R. This instruction includes an example of how to write a simple script to create a temperature conversion function.

Tip: If you are developing scripts using TIBCO Enterprise Runtime for R, you can use RStudio, a full-featured, open-source integrated development environment for working with R code. It is provided independently of TIBCO Software Inc. You can configure RStudio to use the TIBCO Enterprise Runtime for R engine and to display its language reference. Also, you can access the TIBCO Enterprise Runtime for R language reference at https://docs.tibco.com/products/tibco-enterprise-runtime-for-r.

  1. In TIBCO Spotfire, select Edit > Data Function Properties.
    Response: The Data Function Properties dialog is displayed.

  2. Click the Expression Functions tab.

  3. Click New....
    Response: The Expression Function dialog is displayed.

  4. Type a Name for your Expression Function.
    Comment: The name of the Expression Function will be shown when browsing the Functions list in the Custom Expression and Insert Calculated Column dialogs.

  5. Select the Function type: A Column function returns the same number of rows as the input, whereas an Aggregation function aggregates the input values into a single output value.

  6. Optionally, type a Description for your Expression Function.
    Comment: The description of the Expression Function is displayed when browsing the Functions list in the Custom Expression and Insert Calculated Column dialogs.

  7. In the Script field, enter the script. For example, paste the following script to create a temperature conversion function:
    # Define the CelsiusToFahrenheit function:
    CelsiusToFahrenheit <- function(TempCelsius)
    {
     TempFahrenheit <- TempCelsius * (9/5) + 32
     TempFahrenheit
     }
    # Run the function to produce the output
    output <- CelsiusToFahrenheit(TempCelsius = input1)
    Comment: Alternatively, you can also call a built-in function from TIBCO Enterprise Runtime for R.

  8. Select Return type to define the Spotfire data type that the script should return.

  9. Comment: Make sure that the output from the script matches the selected return type. For example, the script in the example will produce a Real value, hence, Real should be selected as the return type.

  10. Select the Category in which to place the function in the function list.

See also:

How to Edit an Expression Function