
Spotfire includes a long list of functions that are available whenever adding a new calculated column or axis expression. It’s also possible to customize this list with your own functions using R.
Spotfire Analyst includes an R runtime called TERR (TIBCO Enterprise Runtime for R). This built-in R engine can be used to execute expressions that have been written in R.
Once defined, they show up in the function list for Custom Expressions and Calculated columns, like this:
They can be used in the expression just like the native functions, complete with its own input arguments and output type:
To define a new custom function, select Edit > Data Function Properties and select the “Expression Functions” tab. Here you’ll be able to add a new function or edit existing ones. Here’s an example of a function that has been added to compute a temperature conversion (click on image for full size):
Custom functions consist of a script using R syntax that includes the function declaration, along with the output assignment. In the above example, the “FahrenheitToCelcius” function is defined to accept a single input variable. Functions can also be written to accept multiple input arguments simply by referring to the input order, like this:
output <- MyCustomFunction(x = input1, y=input2, x=input3)
The configuration of the custom function also allows you to specify a description that will show up in the Expression window. This can be used to include a usage example that may be helpful to others who are using the function.
There’s a lot more information available on how to write your own custom functions with R. See the below reference links for free online training, along with a link to the full TERR syntax reference.
Reference: